Basics done? Next come CASE WHEN, CTEs and window functions, where SQL rounds get harder.
Two hours a day, one dataset, 14 days.
Start Day 1 tonight.
The 14-day plan
- D1-2
CASE WHEN
- CASE WHEN inside SELECT
- Turn rows into columns
- SUM(CASE WHEN ... THEN 1 ELSE 0 END)
- D3-4
Subqueries and CTEs
- Subquery in WHERE and FROM
- WITH ... AS, chain 2-3 CTEs
- EXISTS vs IN
- D5-8
Ranking window functions
- ROW_NUMBER, RANK, DENSE_RANK
- PARTITION BY to rank inside groups
- Top N per group
- D9-11
Running totals
- Running total with SUM() OVER
- 3-month moving average
- LAG / LEAD for month-over-month
- D12-14
Dates + mocks
- Month buckets, first purchase month
- COALESCE and NULLs in counts
- 20 timed problems, out loud
The 2 queries to master
- 01
Top 3 per category
DENSE_RANK keeps ties together.
WITH r AS ( SELECT category, product, sales, DENSE_RANK() OVER ( PARTITION BY category ORDER BY sales DESC) AS rk FROM product_sales) SELECT * FROM r WHERE rk <= 3; - 02
Month-over-month change
First month is NULL: nothing before it.
SELECT month, revenue, revenue - LAG(revenue) OVER ( ORDER BY month) AS change FROM monthly_revenue;
Practise both live: rank inside each department and month-over-month change.
Your daily 2 hours
| Block | What you do |
|---|---|
| 30 min | Learn the day's topic |
| 60 min | Solve 8-10 problems yourself |
| 20 min | Rewrite one answer shorter |
| 10 min | Log every mistake in one sheet |
Same dataset all 14 days. Only the skill changes.
How to practise
Wastes the 14 days
- Reading the solution first
- Only easy problems
- Never testing NULLs and duplicates
Works
- Typing every query yourself
- One medium problem daily
- Testing NULLs and duplicates