Revenue by channel, without double-counting
You have `orders`, `order_items`, `customers` and `channels`. Produce monthly revenue by acquisition channel for the last 12 months, including channels with no revenue in a given month. The trap is deliberate: orders have many items, and a naive join will triple your revenue. Your submission should make it obvious to a reviewer that this did not happen to you.
What you have to hand in
- One row per channel per month for the last 12 months, with no gaps.
- Revenue matches the order-level total to the penny.
- Channels with zero revenue in a month appear with 0, not absent.
- The submission includes at least one check you ran to verify the grain.
The checklist, published before you start
- Result grain is correct
The output has exactly one row per intended entity, and joins have not inflated any aggregate.
- Totals are inflated by fan-out, or the grain is not stated anywhere.
- Grain is right for some columns but at least one aggregate double-counts.
- Grain is correct throughout and stated in a comment or the write-up.
- Grain is correct, stated, and explicitly verified in the submission.
- Answers the question asked
The numbers returned are the numbers the brief asked for, over the right population and period.
- Answers a different question, or the population is wrong.
- Broadly right but the filter or period is off.
- Correct figures over the correct population and period.
- Correct, and edge cases in the brief (refunds, cancellations) are handled deliberately.
- Missing data is handled deliberately
NULLs and absent rows are handled on purpose, not by accident.
- NULLs silently drop rows or produce NULL totals.
- Some NULL handling, applied inconsistently.
- NULLs handled correctly wherever they can occur.
- NULL handling is correct and the choice is justified in the write-up.
- A colleague could maintain it
CTEs or subqueries are named for what they answer; the query can be read top to bottom.
- One long query with no structure, or names like `t1`, `a`, `x`.
- Some structure, but the reader has to hold too much in their head.
- Clear steps with meaningful names.
- Reads like an explanation of the analysis, not just an implementation of it.
- The result was checked
The submission shows evidence that the author verified the number before trusting it.
- No sign the result was checked at all.
- A check is mentioned but not shown.
- At least one concrete check is shown with its output.
- Multiple independent checks, including one that would have caught a grain error.
The skills a pass would prove
- Join grain and fan-outJoin three tables at the correct grain and prove the totals were not inflated by fan-out
- GROUP BY and result grainState the grain of a result set and write the GROUP BY that produces it
- Outer joinsPreserve unmatched rows with an outer join without accidentally filtering them back out
- Validating a resultCheck a query result for correctness before trusting it, and say what you checked
This brief is part of the SQL & Data Analysis course
Starting it starts the course: every skill above, in the order they depend on each other, with this brief at the end as the thing you hand in — marked against the checklist you have just read and nothing else.
Start the SQL & Data Analysis course