Practice Guide

The earlier lessons each cover one piece of syntax. The problems here are given like requests at work: only the result you want is described, and you decide which syntax to combine and how. They use joins, aggregation, subqueries, set operations, WITH, window functions and ROLLUP together.

How to solve

  1. Read the problem's Requirements and Result format (column order, sort order).
  2. Edit My solution, opened in the editor. The SQL it starts with is only a starting point, not the answer.
  3. Run it with Ctrl+Enter (or Run). A check card appears above the result.
  4. If it is wrong, the card tells you what differs (columns, rows, values, order). Show the expected result lists the rows the answer query returned, and if you are stuck, open Show the answer SQL under the problem.

How the check works

  • The answer query runs once on the same DB and your result is compared with it. The sandboxes hold slightly different data, so results are never compared across DBs.
  • Columns are compared by position. Different column names still pass if the values match, but the card tells you the names differ.
  • Numbers are compared by value: 12, 12.0 and a string '12' are equal. A different rounding gives a different value.
  • When a problem gives a sort order, the order must match too. A problem that says "order does not matter" compares the set of rows only.
  • The whole result must be fetched to be compared. Practice pages start with Fetch set to All rows.
  • When the script has several statements, the last one is checked.

Problems

ProblemScenarioMain syntax
Practice 1Monthly VIP sales and change from the previous monthJoins, GROUP BY, string functions, LAG
Practice 2Top 3 customers per regionWITH, ROW_NUMBER, PARTITION BY
Practice 3Login streaks of 3 days or moreDISTINCT, gaps and islands, HAVING
Practice 4VIPs who stopped buying this yearNOT EXISTS, outer joins, aggregation
Practice 5Grade × order status table with a total rowCASE pivot, ROLLUP, GROUPING
Practice 6Headcount and salary under each managerRecursive WITH, joins, aggregation
Practice 7VIPs who bought in Jan and Feb but not in MarchINTERSECT, EXCEPT, IN subqueries

The tables are customers (100K rows) and orders (2M rows) from the common environment; some problems use a small table built with VALUES. The order number ord_no is YYYYMMDD followed by an 8-digit serial, so its first 4 or 6 characters filter by year or month.