SQL Playground Mission: Revenue Audit Report
Build a monthly shipped-revenue audit from order line items.
Revenue reports usually come from line items, not just orders. The order row says when the purchase happened and whether it shipped; the line-item rows say what each order was worth.
This mission combines a filter, a join, date bucketing, a sum, and a distinct order count. It is a realistic audit pattern: state the population first (shipped orders), then summarize only those rows.
select date_bucket,
round(sum(quantity * unit_price), 2) as revenue,
count(distinct order_id) as orders
from order_lines
where status = 'shipped'
group by date_bucket
order by date_bucket Schema · Garden Shop Table · orders 6 columns · 24 rows
One row per order. Unshipped orders have a null shipped_date.
Schema Table · order_items 5 columns · 48 rows
One row per line item within an order.
Return monthly shipped revenue. Use order_month,
revenue, and orders. Revenue is
quantity * unit_price rounded to two decimals. Sort by month.
Run your query to inspect the result.
Expected answer
- Columns: order_month, revenue, orders.
- Rows: 6 months, January through June 2024.
- June has the highest shipped revenue at 188.
Related
COUNT, SUM, AVG, MIN, MAX, GROUP BY, and HAVING.
COUNT, SUM, AVG, GROUP BY, and HAVING.
Practice aggregate reports, HAVING, and answer shape.
Avoid truncating fractional results.
Group or aggregate every selected column.
Nested SELECTs, IN, EXISTS, and correlation.