Topics / 🗄️ SQL, pandas & Data Analysis / 📈 Level 17: Analyst's SQL

SQL exercise · about 5 minutes · free

Revenue by Month

'How did we do last month?' is the most common question an analyst gets. It starts with grouping by month.

Dates are often stored as text like 2026-03-15. In SQLite, strftime('%Y-%m', order_date) turns a date into its month, and you can group by that.

Table. orders (14 rows): order_date, amount; 2026-01-05 | 300; 2026-01-12 | 500; 2026-01-20 | 300; 2026-02-03 | 150; … | …. Operation: strftime('%Y-%m') + SUM. Result revenue: month, revenue; 2026-01 | 1100; 2026-02 | 750; 2026-03 | 1450; 2026-04 | 1250orders (14 rows)order_dateamount2026-01-053002026-01-125002026-01-203002026-02-03150……revenuemonthrevenue2026-0111002026-027502026-0314502026-041250strftime('%Y-%m') + SUM
Your quest: Show each month (YYYY-MM) and its total revenue as revenue from orders, oldest month first.
Starter code
-- group orders by month
-- Run this first to see the orders table, then change it to answer the task.
SELECT *
FROM orders
LIMIT 5;

Try it in your browser → Free. Sign in with Google to run it. Your code runs on your device.

In this level you'll learn:
More in Level 17: Analyst's SQL

Share on LinkedIn