Orders by status
EasyAggregationE-commerce
The problem
For each order status, show the number of orders and their total amount.
Name the columns status, order_count and total_amount.
Learn this in the course: Metrics, dimensions and grain (video and notes) · Aggregation and GROUP BY (video and notes)
Tables · Online shop
Click a table or column name to insert it into your query.
- INTEGER · primary key
- TEXT
- TEXT · can be NULL
- DATE
Sample rows (10 total)
| customer_id | name | city | signup_date |
|---|---|---|---|
| 1 | Aarav Mehta | Mumbai | 2025-01-10 |
| 2 | Diya Nair | Bengaluru | 2025-01-18 |
| 3 | Kabir Singh | Delhi | 2025-02-02 |
| 4 | Meera Iyer | Chennai | 2025-02-14 |
| 5 | Rohan Das | Kolkata | 2025-03-01 |
- INTEGER · primary key
- INTEGER · → customers
- DATE
- TEXT · delivered | cancelled | returned | pending
- INTEGER · rupees
Sample rows (20 total)
| order_id | customer_id | order_date | status | amount |
|---|---|---|---|---|
| 1 | 1 | 2025-05-01 | delivered | 1200 |
| 2 | 1 | 2025-05-15 | delivered | 800 |
| 3 | 1 | 2025-06-02 | cancelled | 500 |
| 4 | 2 | 2025-05-03 | delivered | 2500 |
| 5 | 2 | 2025-05-20 | delivered | 450 |
Ctrl/⌘ + Enter runs the query. Table and column names are suggested as you type. Press Esc then Tab to leave the editor with the keyboard.
Expected output (4 rows)
| status | order_count | total_amount |
|---|---|---|
| delivered | 14 | 17000 |
| cancelled | 2 | 2700 |
| returned | 2 | 2150 |
| pending | 2 | 1400 |
Row order doesn’t matter for this question. Numbers are compared with a tiny tolerance; text must match exactly.
Stuck?
Stored on this device only. Your latest query and “solved” status are remembered in this browser only. They don’t sync between devices, and clearing your browser data removes them.