SQL Lab
Real Postgres runs in your browser with four practice databases: a food-delivery app, a UPI wallet, a cricket league and train bookings. Write the SQL, run it, and the lab checks your answer on a fresh copy of the data.
- 1Read the task and write your SQL.
- 2Run it as often as you like to see what comes back.
- 3Check it: the lab compares your result with the right one.
SQL from zero
- Write a queryBeginnerRatings out of 10
Practises: Your first query: SELECT
Open exercise - Write a queryBeginnerCard and wallet orders on 31 October
Practises: Picking rows with WHERE
Open exercise - Write a queryBeginnerBengaluru's top 5
Practises: Sorting, top N and DISTINCT
Open exercise - Write a queryBeginnerEvery order except SWAAD50
Practises: NULL, the missing value
Open exercise - Write a queryBeginnerDiwali orders by hour and size
Practises: Types, dates and everyday functions
Open exercise
Combining and summing
- Write a queryBeginnerNovember's takings
Practises: Counting and summing
Open exercise - Write a queryBeginnerPayment methods with over 2,000 deliveries
Practises: GROUP BY and HAVING
Open exercise - Write a queryIntermediateEvery Pune restaurant's December
Practises: LEFT JOIN and finding what's missing
Open exercise - Write a queryIntermediateUsers nobody has paid
Practises: Subqueries, EXISTS and WITH
Open exercise - Write a queryIntermediateTop three scorers each season
Practises: Window functions
Open exercise
Changing data safely
- Change the dataBeginnerTake coupons off cancelled orders
Practises: Adding, changing and removing rows
Open exercise - Design tablesBeginnerA wallet the database protects
Practises: Rules the database enforces
Open exercise - Design tablesIntermediateA new rule on old data
Practises: Rules the database enforces
Open exercise - Change the dataIntermediatePay a friend, all or nothing
Practises: Transactions: all or nothing
Open exercise - Design tablesAdvancedOne confirmed ticket per berth
Practises: When everyone books at once
Open exercise
Designing schemas
- Design tablesIntermediateFavourite restaurants
Practises: From an app to tables
Open exercise - Design tablesIntermediateSplit the order sheet
Practises: Normalisation: one fact in one place
Open exercise - Change the dataIntermediateA stored order count
Practises: When to break the rules
Open exercise - Design tablesAdvancedSoft-deleted dishes
Practises: Patterns: history, soft deletes and JSON
Open exercise - Design tablesAdvancedThe core of a ledger
Practises: Modelling money: a wallet ledger
Open exercise
Making queries fast
- Make it fastIntermediateSpeed up Your orders
Practises: How an index works
Open exercise - Make it fastAdvancedThe on-the-way board
Practises: Composite, covering and partial indexes
Open exercise - Make it fastAdvancedA report you can't rewrite
Practises: When indexes don't help
Open exercise - Write a queryIntermediateOne query, not fifty
Practises: N+1 queries and talking from code
Open exercise - Write a queryAdvancedThe next page, without OFFSET
Practises: Fast pagination
Open exercise
Inside the database
- Change the dataIntermediatePay only if the balance covers it
Practises: MVCC: many versions of a row
Open exercise - Change the dataAdvancedTune autovacuum for a busy table
Practises: Dead rows and VACUUM
Open exercise - Make it fastIntermediateKeep the tracking screen on a few pages
Practises: Memory and the buffer cache
Open exercise - Write a queryIntermediateRead the planner's notes on NULLs
Practises: How the planner chooses
Open exercise - Make it fastAdvancedThe login that hid its column
Practises: How the planner chooses
Open exercise
Running databases
- Change the dataIntermediateAn app role that can't delete orders
Practises: Backups and point-in-time recovery
Open exercise - Write a queryIntermediateWho blocks the phone rule?
Practises: Changing a live schema safely
Open exercise - Change the dataIntermediateThe first batch of a backfill
Practises: Changing a live schema safely
Open exercise - Design tablesAdvancedBills partitioned by month
Practises: Partitioning big tables
Open exercise - Change the dataAdvancedMove six months into partitions
Practises: Partitioning big tables
Open exercise
Beyond tables
- Write a queryIntermediateSearch inside order documents
Practises: Document databases and JSON
Open exercise - Write a queryIntermediateSearch the menu for egg rolls
Practises: Search and inverted indexes
Open exercise - Make it fastIntermediateMake review search fast
Practises: Search and inverted indexes
Open exercise - Write a queryAdvancedQuarter report with subtotals
Practises: Analytics: rows versus columns
Open exercise - Write a queryAdvancedWhere can you go with one change?
Practises: Graphs and recursive queries
Open exercise
Exercises for free lessons are open once you sign in; the rest are part of SDQ Pro.