We use analytics and advertising cookies to understand how the site is used and whether our ads on Facebook and Instagram work. They are set only if you accept. See our Privacy Policy for details.
A CASE expression returns a value per row based on the first WHEN that matches - labeling orders by size, mapping text priorities to a sort rank, or bucketing totals into tiers. Wrapped in SUM or COUNT it becomes conditional aggregation, the standard way to pivot rows into columns ("revenue per month as columns"), and data and analytics screens ask for it constantly. The traps interviewers watch for are branch order (the first match wins) and a missing ELSE that turns 0 into NULL.
5 problems across 3 schemas · 1 free for registered users. Each runs your query in an isolated SQLite sandbox with instant, graded feedback.
A quick data question to warm up before you write SQL. No signup needed.
Product data arrives in three normalised source tables: product, subcategory and category. The reporting model needs a single product dimension, and a product's category history must be kept when it changes. How should the data be prepared?
Keep the syntax at your fingertips with the free SQL quick references, then come back and solve.