All · Practice · SQL

SQL 20

Twenty interview-style SQL problems, from filters and joins to window functions and streaks.

  • Free
  • Beginner to advanced
  • 5h
  • 20 problems

What you’ll learn

  • Handle NULLs, anti-joins and conditional aggregation without the usual traps
  • Use window functions for ranking, running totals, period-over-period change and latest-row-per-key
  • Solve gaps-and-islands and date-bucket questions that harder interviews ask
  • Check a query against edge cases before calling it done

About this course

Each problem shows its tables and sample data. You write a query in the editor, run it on the sample, then submit: it is checked on the sample and on hidden data sets with the edge cases that catch common mistakes (NULLs, ties, empty groups, month boundaries).

The problems run from easy filters to the window-function and streak questions that come up in harder data interviews. Hints build up one at a time, and every problem has a worked solution that explains the technique and the usual mistake.

Queries run in a PostgreSQL-like SQL engine (DuckDB) inside your browser.

Syllabus

4 units, about 5 hours.

1Warm-up: filters, NULLs and simple aggregation6 lessons1h 4m
  • Overdue Unpaid Invoices
  • Best Way to Reach Each Customer
  • Sign-ups per Email Domain
  • Customers With Three Completed Orders
  • Policies That Never Claimed
  • Share of Claim Payouts by Cause
2Joins, subqueries and pivots4 lessons1h 5m
  • Orders Above the Customer's Own Average
  • Came Back Within a Week
  • Possible Duplicate Claims
  • Claim Status Counts by Line of Business
3Window functions6 lessons1h 36m
  • Running Balance per Account
  • Top Customer in Each City
  • Top Two Premium Totals in Each Region
  • Current Mailing Address
  • First and Current Subscription Plan
  • Month-over-Month Payment Revenue
4Harder: streaks, gaps and missing data4 lessons1h 40m
  • Longest Run of Workout Days
  • Gaps in Insurance Coverage
  • Fill Missing Sensor Readings
  • Seven-Day Energy Average With Missing Days

Who it’s for

All, at Beginner to advanced level.

Time needed

Self-paced, with no start dates or deadlines. Working through everything takes about 5 hours in total; the syllabus shows the time for each unit.

More like this

Related courses

All Practice courses
Practice

All · Algorithms and data structures

Core Patterns 40

Forty original coding problems arranged by the patterns that coding interviews at large tech companies keep returning to: hashing, two pointers, sliding window, prefix sums, stacks, binary search, intervals, linked lists, trees, tries, heaps, graphs, backtracking, dynamic programming and bit tricks. Write your solution in Python or JavaScript in the browser; it runs against hidden tests, including large ones that a slow brute force will not pass.

  • Beginner to intermediate
  • 13h
  • 40 problems
  • Practice
Free
Practice

All · Puzzles

Logic and Probability Puzzles 30

Thirty original puzzles: weighing and deduction, switches and lamps, dice and card games, expected waiting times, optimal stopping, Fermi estimates and mental maths. Quant trading firms, analytics teams and consulting interviews use puzzles like these to see how you reason. Give your answer as a number, fraction or choice, then read the worked solution.

  • Beginner to advanced
  • 4h
  • 30 problems
  • Practice
Free