General ML questions. Some SQL queries.
Using the provided users and orders tables, write a PostgreSQL query that returns users with at least two completed orders. Include only completed orders when calculating the requested metrics. Handle nullable order amounts according to standard PostgreSQL aggregate behavior.
user_id, user_name, completed_order_count, total_spend, avg_order_value, and latest_order_date.total_spend descending, then user_id ascending.| Column | Type | Description |
|---|---|---|
| user_idPK | INT | Unique user identifier |
| user_name | VARCHAR(100) | User display name |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| user_id | INT | User associated with the order |
| order_status | VARCHAR(20) | Current order status |
| amount | DECIMAL(10,2) | Order amount |
| order_date | DATE | Date the order was placed |