Backend track

SQL practice

15 problems 3 difficulty levels 11 topics

Write the query, run it, see the rows. Every problem here ships with a seeded Postgres database that runs inside your browser — nothing to install, no account needed to run a query.

How grading works

Your query is judged on the rows it returns, never on the text you typed. There is no single expected answer string: if your query produces the right result set, it passes, however you wrote it.

  • Row order only matters when the problem asks for an order. Otherwise any permutation passes.
  • Column names never fail a submission. Alias a column however you like.
  • Duplicates count. Rows are compared as a multiset, so an extra duplicate row is a wrong answer.
  • The database resets before every run. A stray DELETE cannot break the next attempt.

Want a scratchpad instead of a problem? The SQL playground gives you the same engine with an empty schema you control.

Problems

Difficulty
Topics
Status
Completion filters become available once your progress has loaded. Saving entries for later is not available on this page yet.

0 of 15 completed

15 results

  • Employees Without a Manager

    List every employee alongside their manager, including the ones who have no manager. A self-join where INNER and LEFT give different answers.

    Joins
    Easy
  • Sales Per Employee

    Count each employee's sales and total their value, including the employees who sold nothing. Getting the zeroes right is the problem.

    Joins Aggregation
    Medium
  • Departments With No Employees

    Find every department that has nobody in it. The obvious NOT IN answer returns nothing — work out why and write one that does not.

    Joins
    Hard
  • Top Earner Per Department

    Return the highest-paid employee in each department. Run your query against a seeded Postgres in your browser and get graded on the rows you return.

    Windows Joins
    Medium
  • Month Over Month Revenue

    Total revenue per month and the change against the previous month. One month has no orders, which is where the obvious answer goes wrong.

    Windows Aggregation
    Medium
  • Revenue and Headcount

    Two aggregates over two different tables in one row per department. Joining both at once multiplies them together — the answer is to not do that.

    CTEs Aggregation Joins
    Hard
  • Recent Hires By Department

    Count each department's hires in a date range and find the most recent one. Then read the plan and work out why the index was not used.

    Indexes Query Plans
    Easy
  • Latest Order Per Customer

    Replace one query per customer with a single query returning every customer's most recent order. Two orders share a date, which decides the tie.

    N+1 Windows
    Medium
  • Rows Blocking a Unique Index

    A migration wants a unique index on email and it fails. Find every duplicate at once instead of one error at a time.

    Indexes Aggregation
    Medium
  • Adjust Salaries Atomically

    Four changes that must all land or none of them. A CHECK on the budget pool means the order you write them in decides whether it commits.

    Transactions
    Medium
  • Merge a Batch Into a Counter

    Add a batch of page-view counts into a daily totals table where some days already exist. One statement, no read-then-write race.

    Transactions Isolation
    Medium
  • Claim a Job From the Queue

    Take the two highest-priority queued jobs for one worker without two workers ever taking the same job and without either of them waiting.

    Locking Transactions
    Hard
  • Query a Comma Separated Column

    Tags are stored as one comma-separated string per article. Find the tags shared by more than one article — and see what the schema costs.

    Schema Design
    Medium
  • Find the Double Booked Rooms

    Nothing stopped two bookings landing on the same room at the same time. Find every conflicting pair — the boundaries are the whole problem.

    Schema Design Joins
    Hard
  • Find the Orphaned Rows

    Three tables, no foreign keys, and a migration about to add them. List every row that would be rejected — and only those.

    Schema Design Joins
    Hard

If a problem is hard, read the lesson first

The bank is a drill, not a course. Each problem links back to the lesson that teaches it, and the SQL track is the ordered path through all of it — joins and aggregation first, then indexes and query plans, then transactions.