Querydrill

SQL business case: the monthly revenue report

Your manager wants the monthly revenue report rebuilt in SQL so it stops living in a spreadsheet. It has four columns that build on each other: revenue per month, the change on the previous month, the running total for the year, and each month's share of the total.

Four exercises, each adding one column to the one before. By the end you have written the report most analysts are asked for in their first week.

0 of 4 solvedStart with step 1

Step 1: Revenue per month

  • Revenue report, step 1: revenue per monthYou are building the monthly revenue report. Start with the base: for each month that has paid orders, return the month as YYYY-MM and the total paid amount, in columns month and revenue.

Step 2: Change on the previous month

  • Revenue report, step 2: change on the previous monthExtend the monthly report. For each month return month, revenue, the previous month's revenue as prev_revenue, and the difference as change (revenue minus prev_revenue). The first month has no previous month, so both extra columns are NULL there.

Step 3: Running total

  • Revenue report, step 3: running totalAdd a year-to-date column. For each month return month, revenue and running_total: the sum of paid revenue from the first month up to and including that month.

Step 4: Share of the total

Other plans and cases

Your first 8 exercises are free, with no account, from any plan or level. Progress is kept in this browser; a free account keeps it on every device.