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.
Subqueries and CASE
Use one query's answer inside another, and label rows by rules.
- Class 1A number from another queryYou are herePlus · Ultra
- Class 2A list from another queryPlus · Ultra
- Class 3A subquery for each rowPlus · Ultra
- Class 4EXISTS and NOT EXISTSPlus · Ultra
- Class 5Sort into bands with CASEPlus · Ultra
- Class 6Fill in missing valuesPlus · Ultra
- Class 7On your own: orders and returns per customerPlus · Ultra
- Level exam · 4 questionsThe account health listPlus · Ultra
CTEs, set operations and joins
Build big queries in named steps, stack lists, and follow links across tables.
Pass the level 1 exam to open this level.
- Class 8Name a step with WITHPlus · Ultra
- Class 9Two steps in a rowPlus · Ultra
- Class 10Stack two lists: UNIONPlus · Ultra
- Class 11Keep the repeats: UNION ALLPlus · Ultra
- Class 12What two lists share: INTERSECTPlus · Ultra
- Class 13A table joined to itselfPlus · Ultra
- Class 14Join four tablesPlus · Ultra
- Class 15Walk a chain: WITH RECURSIVEPlus · Ultra
- Class 16On your own: sales per teamPlus · Ultra
- Level exam · 4 questionsThe slow sellers reviewPlus · Ultra
Window functions
Rank, number, run totals and compare rows, without losing a single row.
Pass the level 2 exam to open this level.
- Class 17Number the rows: ROW_NUMBERPlus · Ultra
- Class 18Ties: RANK and DENSE_RANKPlus · Ultra
- Class 19Restart for each group: PARTITION BYPlus · Ultra
- Class 20A running totalPlus · Ultra
- Class 21A moving averagePlus · Ultra
- Class 22Compare with the row before: LAGPlus · Ultra
- Class 23The next order for each customer: LEADPlus · Ultra
- Class 24The best in each groupPlus · Ultra
- Class 25On your own: the sales leaderboardPlus · Ultra
- Level exam · 4 questionsThe customer order historyPlus · Ultra
Dates, text and cleaning
Report by month, measure gaps, clean messy text and remove duplicates.
Pass the level 3 exam to open this level.
- Class 26Group by month: strftimePlus · Ultra
- Class 27Days between two datesPlus · Ultra
- Class 28The last 30 daysPlus · Ultra
- Class 29Clean up textPlus · Ultra
- Class 30Pull out a part: SUBSTR and INSTRPlus · Ultra
- Class 31Find and remove duplicatesPlus · Ultra
- Class 32Turn rows into columnsPlus · Ultra
- Class 33On your own: the monthly service reportPlus · Ultra
- Level exam · 4 questionsThe second-quarter reviewPlus · Ultra
Design, safety and speed
Tables with rules, changes that are all or nothing, saved queries and fast lookups.
Pass the level 4 exam to open this level.
- Class 34Rules inside the tablePlus · Ultra
- Class 35Links that must exist: FOREIGN KEYPlus · Ultra
- Class 36All or nothing: a transactionPlus · Ultra
- Class 37Insert or update: ON CONFLICTPlus · Ultra
- Class 38Save a query as a VIEWPlus · Ultra
- Class 39Speed up a lookup: CREATE INDEXPlus · Ultra
- Class 40Take it to a real machine: SQLite on your computerPlus · Ultra
- Class 41On your own: the margin reportPlus · Ultra
- Level exam · 4 questionsCourse exam: the monthly sales packPlus · Ultra

