Data · Advanced

Advanced SQL

Subqueries, CTEs, window functions, date and text work, and safe table design, on a real company database.

What runs here: Real SQLite runs in your browser, and your query is checked again on other copies of the data.

  • 5 levels
  • 41 hands-on classes
  • 5 level exams
  • about 8 h

What you'll be able to doWrite the queries analysts use every day: subqueries, CTEs, window functions, date and text work, and safe, fast tables.

0%Not started
Level 1 · 7 classes and an exam

Subqueries and CASE

Use one query's answer inside another, and label rows by rules.

0/8

Recap of this level

  1. Class 1A number from another queryYou are herePlus · Ultra
  2. Class 2A list from another queryPlus · Ultra
  3. Class 3A subquery for each rowPlus · Ultra
  4. Class 4EXISTS and NOT EXISTSPlus · Ultra
  5. Class 5Sort into bands with CASEPlus · Ultra
  6. Class 6Fill in missing valuesPlus · Ultra
  7. Class 7On your own: orders and returns per customerPlus · Ultra
  8. Level exam · 4 questionsThe account health listPlus · Ultra
Level 2 · 9 classes and an exam

CTEs, set operations and joins

Build big queries in named steps, stack lists, and follow links across tables.

0/10

Recap of this level

Pass the level 1 exam to open this level.

  1. Class 8Name a step with WITHPlus · Ultra
  2. Class 9Two steps in a rowPlus · Ultra
  3. Class 10Stack two lists: UNIONPlus · Ultra
  4. Class 11Keep the repeats: UNION ALLPlus · Ultra
  5. Class 12What two lists share: INTERSECTPlus · Ultra
  6. Class 13A table joined to itselfPlus · Ultra
  7. Class 14Join four tablesPlus · Ultra
  8. Class 15Walk a chain: WITH RECURSIVEPlus · Ultra
  9. Class 16On your own: sales per teamPlus · Ultra
  10. Level exam · 4 questionsThe slow sellers reviewPlus · Ultra
Level 3 · 9 classes and an exam

Window functions

Rank, number, run totals and compare rows, without losing a single row.

0/10

Recap of this level

Pass the level 2 exam to open this level.

  1. Class 17Number the rows: ROW_NUMBERPlus · Ultra
  2. Class 18Ties: RANK and DENSE_RANKPlus · Ultra
  3. Class 19Restart for each group: PARTITION BYPlus · Ultra
  4. Class 20A running totalPlus · Ultra
  5. Class 21A moving averagePlus · Ultra
  6. Class 22Compare with the row before: LAGPlus · Ultra
  7. Class 23The next order for each customer: LEADPlus · Ultra
  8. Class 24The best in each groupPlus · Ultra
  9. Class 25On your own: the sales leaderboardPlus · Ultra
  10. Level exam · 4 questionsThe customer order historyPlus · Ultra
Level 4 · 8 classes and an exam

Dates, text and cleaning

Report by month, measure gaps, clean messy text and remove duplicates.

0/9

Recap of this level

Pass the level 3 exam to open this level.

  1. Class 26Group by month: strftimePlus · Ultra
  2. Class 27Days between two datesPlus · Ultra
  3. Class 28The last 30 daysPlus · Ultra
  4. Class 29Clean up textPlus · Ultra
  5. Class 30Pull out a part: SUBSTR and INSTRPlus · Ultra
  6. Class 31Find and remove duplicatesPlus · Ultra
  7. Class 32Turn rows into columnsPlus · Ultra
  8. Class 33On your own: the monthly service reportPlus · Ultra
  9. Level exam · 4 questionsThe second-quarter reviewPlus · Ultra
Level 5 · 8 classes and an exam

Design, safety and speed

Tables with rules, changes that are all or nothing, saved queries and fast lookups.

0/9

Recap of this level

Pass the level 4 exam to open this level.

  1. Class 34Rules inside the tablePlus · Ultra
  2. Class 35Links that must exist: FOREIGN KEYPlus · Ultra
  3. Class 36All or nothing: a transactionPlus · Ultra
  4. Class 37Insert or update: ON CONFLICTPlus · Ultra
  5. Class 38Save a query as a VIEWPlus · Ultra
  6. Class 39Speed up a lookup: CREATE INDEXPlus · Ultra
  7. Class 40Take it to a real machine: SQLite on your computerPlus · Ultra
  8. Class 41On your own: the margin reportPlus · Ultra
  9. Level exam · 4 questionsCourse exam: the monthly sales packPlus · Ultra
Finish line: Advanced SQLEach level exam you pass gives you that level's trophy. Pass every level exam to finish the course and graduate.