Beginner Case 16 of 50

Case 016: Revenue by Month

orderspayments

Leadership wants a trend line for the board meeting, and the manager brings the request to Alex.

"Rather than one number, could you show me revenue month by month?"

The data Alex is looking at

orders
idcustomer_idorder_date
10112026-01-05
10222026-01-08
10332026-01-12
10412026-01-20
10542026-02-01
… 23 more rows
payments
idorder_idamount
6011016200
6021023500
6031033600
60410460000
60510512000
… 23 more rows
TASK

Help Alex answer the manager:

“Show total revenue for each calendar month.”
SQL editor Ctrl+Enter to run
Write a query above and hit Run to see what comes back.
No hints requested yet — click "Get a hint" when you're stuck.
Alex's final query — this is for reference. Copy it into your own thinking, not into the editor above.
SELECT DATE_FORMAT(orders.order_date, '%Y-%m') AS month, SUM(payments.amount) AS revenue FROM orders JOIN payments ON payments.order_id = orders.id GROUP BY month ORDER BY month;
What that query returns
Case Debrief Date functions, grouping by time period
  • DATE_FORMAT() (a date-formatting function) lets you group timestamps by year, month, day, or any pattern you need.
  • Quick tip: DATE_FORMAT() itself is MySQL-specific — here's the same "year-month" formatting in other major databases.
    • Postgres / Snowflake: TO_CHAR(order_date, 'YYYY-MM')
    • SQL Server: FORMAT(order_date, 'yyyy-MM')

Case closed.

Ready for the next one?

Next: Case 017 — The Loyal High-Value Customers →