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
- Read the problem's Requirements and Result format (column order, sort order).
- Edit My solution, opened in the editor. The SQL it starts with is only a starting point, not the answer.
- Run it with
Ctrl+Enter(or Run). A check card appears above the result. - 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.0and 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
| Problem | Scenario | Main syntax |
|---|---|---|
| Practice 1 | Monthly VIP sales and change from the previous month | Joins, GROUP BY, string functions, LAG |
| Practice 2 | Top 3 customers per region | WITH, ROW_NUMBER, PARTITION BY |
| Practice 3 | Login streaks of 3 days or more | DISTINCT, gaps and islands, HAVING |
| Practice 4 | VIPs who stopped buying this year | NOT EXISTS, outer joins, aggregation |
| Practice 5 | Grade × order status table with a total row | CASE pivot, ROLLUP, GROUPING |
| Practice 6 | Headcount and salary under each manager | Recursive WITH, joins, aggregation |
| Practice 7 | VIPs who bought in Jan and Feb but not in March | INTERSECT, 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.