Your question is Revenue and Order Status Counts. Start with the requirements and the two tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Tesla Online Store operations needs a daily view of order activity. Order revenue is stored at the line-item level, while order status and date are stored in the orders table.
Write a PostgreSQL query to report one row per order date.
total_completed_revenue by summing quantity * unit_price only for completed orders.pending_order_count and cancelled orders as cancelled_order_count.order_date.Pre-aggregate line items before joining them to orders so an order with multiple items does not inflate status counts.
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| order_date | DATE | Date the order was placed |
| status | VARCHAR(20) | Current order status |
| sales_channel | VARCHAR(30) | Tesla sales channel |
| Column | Type | Description |
|---|---|---|
| item_idPK | INT | Unique line-item identifier |
| order_id | INT | References orders.order_id |
| quantity | INT | Number of units ordered |
| unit_price | NUMERIC(10,2) | Price for one unit |