HCL needs a sales ranking for customers using data from its commerce platform. Write a PostgreSQL query that identifies the top 10 customers by sales from completed orders.
quantity * unit_price.status = 'completed'; treat a NULL unit price as zero.customer_id.| 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) | Current order status |
| Column | Type | Description |
|---|---|---|
| order_item_idPK | INT | Unique order-line identifier |
| order_id | INT | Order containing the item |
| quantity | INT | Number of units purchased |
| unit_price | NUMERIC(10,2) | Price per unit at purchase time |