Data Analyst / Engineer · Focus area 3: Analytics and dashboards
DT8: Advanced SQL for analysis
Goal: answer real business questions in SQL that others can read and check: break queries into named steps, use window functions for rankings, running totals and changes, build cohort and funnel analyses, and avoid the traps that make a correct-looking number wrong.
You'll need: DT5, DT6, Module 55 (SQL Fundamentals), Module 56 (Advanced Queries), and the SabziSathi practice kit.
Where this is used: "top three products in each store", "how many customers who joined in October ordered again", "where do people drop out of checkout". Questions like these come up every week in every business with data, and SQL is the common language for answering them.
How it differs: an app runs the same few queries millions of times. An analyst writes new queries every day, so readability, checking and knowing the traps matter more than raw speed.
Time: reading about 2½ hours · practice (the Try it tasks) about 3 hours · assignment about 3 hours.
Lessons
- 1Readable queries with CTEsReading 15–25 minutes, plus practice✓
- 2Window functionsReading 15–25 minutes, plus practice✓
- 3Cohorts and retentionReading 15–25 minutes, plus practice✓
- 4Funnels and conversionReading 15–25 minutes, plus practice✓
- 5Traps that make numbers wrongReading 15–25 minutes, plus practice✓
🛠️Assignment: Answers for SabziSathi's managers
This assignment is part of Project 3's preparation.
- Write, as CTEs, the top three products per store by net revenue, with
rank(). - Write daily net revenue with the day-on-day change and a 7-day moving average.
- Build the weekly cohort table of first delivered orders, as counts and percentages, with your caveats written beside it.
- Write one query that falls into a trap from Lesson 5 and its corrected version, with the row counts or totals of both.
- Put all four in
docs/analysis.md, each with the question, the SQL, the result and one sentence a manager could act on.
Self-check before you finish:
- [ ] Every query is split into named steps you've counted.
- [ ] Your top-three list handles ties.
- [ ] Your cohort caveats mention where the data starts and incomplete weeks.
- [ ] Every join has a row check.
- [ ] Every result says it comes from synthetic practice data.
✅Module check
Explain in a few sentences, in your own words:
How do you write analysis SQL that others can trust?
Show a good answer
A good answer mentions: named CTE steps with row checks; window functions for ranks (with ties handled), running totals, moving
averages and changes; cohorts by first period with caveats about where data starts and incomplete periods; funnels that count distinct
people and require earlier steps; and avoiding fan-out, NULL traps, not in with NULLs, averages of averages, adding distinct counts,
timestamp boundaries and integer division.
📚Official references
Official documentation and guidance for this module's topics, chosen on 2 November 2026. Tools, laws and standards change, so check the current version before you rely on a detail. If a link has moved, search the same site.
📝Module quiz
10 questions · 10 marks each · 100 marks in all · pass mark 70% · retry as often as you like ·
