Explain how you would use GROUP BY and HAVING in a SQL query, and when you would choose each.
Using the provided customers and orders tables, write a query that returns customers with at least two completed orders and more than 500 in completed order value.
customer_id, customer_name, completed_order_count, and total_completed_amount.total_completed_amount descending, then customer_id ascending.| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| customer_name | VARCHAR(100) | Customer display name |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| customer_id | INT | Customer associated with the order |
| status | VARCHAR(20) | Order processing status |
| amount | NUMERIC(10,2) | Order value |