Store delivery scorecard
Store delivery scorecard
You are a data analyst at a convenience store chain. The head of operations is preparing a weekly summary of online orders and wants a per-store picture: how many orders were placed in total, how many reached the customer, how many were cancelled, and how much revenue came from delivered orders only. The data lives in the orders table: one row per order, status is one of 'delivered', 'cancelled', 'returned', and the order amount is always present (never NULL).
Conditional metrics are computed with conditional aggregation: a CASE expression inside an aggregate function.
Return columns:
- store — store name (text);
- total_orders — total number of the store's orders (integer);
- delivered_cnt — number of orders with status 'delivered' (integer);
- cancelled_cnt — number of orders with status 'cancelled' (integer);
- delivered_revenue — sum of amount over delivered orders only, rounded to 2 decimals; 0 if the store has no delivered orders.
Sorting: by store ascending. Every store present in the table appears exactly once; the 'returned' status only contributes to total_orders.
Expected output sample
This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables. Your answer must use the same column names as this sample — alias them with AS if needed.
| store | total_orders | delivered_cnt | cancelled_cnt | delivered_revenue |
|---|---|---|---|---|
| downtown | 5 | 3 | 1 | 245.5 |
| harbor | 4 | 2 | 2 | 259.5 |
| uptown | 6 | 3 | 1 | 206 |
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign in