Become a data analyst in 90 days✦27 portfolio projects✦100+ interview Q&As✦1:1 mentor for a year✦See the 90-Day System →✦Become a data analyst in 90 days✦27 portfolio projects✦100+ interview Q&As✦1:1 mentor for a year✦See the 90-Day System →✦
New here? Want every day planned for you? See the 90-Day System →

Free PDF · Advanced SQL

Advanced SQL in 14 days

For when SELECT, WHERE and GROUP BY already feel easy.

DGSQLAdvanced SQL, day by day14@thedataguy16

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

  1. D1-2

    CASE WHEN

    • CASE WHEN inside SELECT
    • Turn rows into columns
    • SUM(CASE WHEN ... THEN 1 ELSE 0 END)
  2. D3-4

    Subqueries and CTEs

    • Subquery in WHERE and FROM
    • WITH ... AS, chain 2-3 CTEs
    • EXISTS vs IN
  3. D5-8

    Ranking window functions

    • ROW_NUMBER, RANK, DENSE_RANK
    • PARTITION BY to rank inside groups
    • Top N per group
  4. D9-11

    Running totals

    • Running total with SUM() OVER
    • 3-month moving average
    • LAG / LEAD for month-over-month
  5. D12-14

    Dates + mocks

    • Month buckets, first purchase month
    • COALESCE and NULLs in counts
    • 20 timed problems, out loud

The 2 queries to master

  1. 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;
  2. 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

BlockWhat you do
30 minLearn the day's topic
60 minSolve 8-10 problems yourself
20 minRewrite one answer shorter
10 minLog 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

Free PDF

Advanced SQL in 14 days

Download the PDF

Opens in Google Drive. No sign-up.

Keep going

More free PDFs

90-Day System · become a data analyst→