Write a query to identify top-performing categories using GROUP BY and HAVING.
Use the provided category and sales data. Include completed sales only, retain categories whose total completed sales are at least 500, and sort the results from highest to lowest total.
category_name, total_salestotal_sales descending, then category_name ascending| Column | Type | Description |
|---|---|---|
| category_idPK | INT | Unique category identifier |
| category_name | VARCHAR(100) | Product category name |
| Column | Type | Description |
|---|---|---|
| sale_idPK | INT | Unique sale identifier |
| category_id | INT | Referenced product category |
| amount | DECIMAL(12,2) | Sale amount |
| status | VARCHAR(20) | Sale processing status |