Home / Learn / Data & AI / SQL for analysts
All lessons

SQL for analysts: from your first SELECT to window functions

Learn SQL by typing it. Every lesson has live editors on a real-looking store database, checks your answers, and shows step by step what each query does to the tables: joins matching rows, groups forming, totals adding up.

For anyone heading into data, BI or analyst work, and for interview practice. No set-up and no sign-up: it runs in your browser. Free, no sign-up. All 52 lessons, about 24.5 hours.

Practice any time: SQL sandbox (the whole Northbay database, with step-by-step pictures) · Quick reference: glossary · cheat sheet

Try it now

Press Run, then Show how it runs to watch the join match rows and the totals add up. Change anything and run it again.

-- try SELECT c.city, COUNT(*) AS orders, SUM(o.amount) AS total FROM mini_orders o JOIN mini_customers c ON o.customer_id = c.id GROUP BY c.city ORDER BY total DESC

What you will be able to do

  • Answer business questions in SQL: filters, summaries, joins across many tables, subqueries and CTEs.
  • Use the SQL that analyst interviews test: window functions, top N per group, running totals, growth, cohorts, funnels and gaps and islands.
  • See what every query does: each step drawn on the tables, so joins and GROUP BY stop being magic.
  • Leave with a portfolio project: the Northbay SQL casebook, 30 business questions answered with your own queries.

Every lesson has live editors with Run, Check, Hint and Show answer, plain-English error messages, and a 3-question quiz. Next steps: Data modelling and warehousing, then Pipeline to Dashboard for the tools that load real warehouses. To query your own CSV or Excel files, use the SQL playground.

0 of 52 lessons done

Without the tick, your progress lasts until you close this tab. Either way it stays in this browser: there is no sign-up and nothing is sent to us.

All modules

Part A: Asking questions of one table

1 Start here 4 lessons

  1. 1.1 What SQL is and why analysts use it
  2. 1.2 Meet Northbay: the practice database
  3. 1.3 Tables, rows, columns and types
  4. 1.4 How a query runs: the order SQL thinks in

2 Picking rows and columns 6 lessons

  1. 2.1 SELECT: choosing columns
  2. 2.2 WHERE: choosing rows
  3. 2.3 AND, OR, IN, BETWEEN and LIKE
  4. 2.4 NULL: the value that isn't there
  5. 2.5 ORDER BY and LIMIT
  6. 2.6 CASE: if-then inside a query

3 Summaries 5 lessons

  1. 3.1 COUNT, SUM, AVG, MIN and MAX
  2. 3.2 GROUP BY: one row per group
  3. 3.3 HAVING: filtering groups
  4. 3.4 COUNT DISTINCT and counting the right thing
  5. 3.5 The grain trap: what one row means

Part B: Combining tables

4 Joins 7 lessons

  1. 4.1 Keys: how tables point at each other
  2. 4.2 INNER JOIN
  3. 4.3 LEFT JOIN and finding what is missing
  4. 4.4 Anti-joins and semi-joins: NOT EXISTS and EXISTS
  5. 4.5 Fan-out: when a join copies rows
  6. 4.6 Self-joins: a table joined to itself
  7. 4.7 UNION, INTERSECT and EXCEPT

5 Subqueries and CTEs 5 lessons

  1. 5.1 Subqueries: a query inside a query
  2. 5.2 IN and EXISTS with subqueries
  3. 5.3 Correlated subqueries
  4. 5.4 CTEs: WITH, step by step
  5. 5.5 Recursive CTEs: calendars and org charts

Part C: Analyst SQL

6 Window functions 7 lessons

  1. 6.1 OVER: totals without losing rows
  2. 6.2 ROW_NUMBER, RANK and DENSE_RANK
  3. 6.3 Top N per group
  4. 6.4 LAG and LEAD: comparing with the row before
  5. 6.5 Running totals and window frames
  6. 6.6 Moving averages
  7. 6.7 Share of total, NTILE and percentiles

7 Dates, text and cleaning 5 lessons

  1. 7.1 Working with dates
  2. 7.2 Text functions
  3. 7.3 Types and CAST
  4. 7.4 Finding and removing duplicates
  5. 7.5 Data quality checks in SQL

8 Patterns analysts use every week 6 lessons

  1. 8.1 Month-over-month and year-over-year growth
  2. 8.2 Cohort retention
  3. 8.3 Funnels and conversion
  4. 8.4 Gaps and islands: streaks and missing days
  5. 8.5 RFM: segmenting customers
  6. 8.6 Pivoting rows into columns

Part D: Real work and interviews

9 Performance and dialects 5 lessons

  1. 9.1 How the database runs your query: EXPLAIN
  2. 9.2 Indexes
  3. 9.3 SQLite, SQL Server, PostgreSQL and BigQuery: what changes
  4. 9.4 Writing SQL other people can read
  5. 9.5 Changing data: INSERT, UPDATE, DELETE and transactions

10 Interview practice and capstone 2 lessons

  1. 10.1 30 SQL interview questions, answered
  2. 10.2 Capstone: the Northbay SQL casebook