Catalog Snapshot Report
Generate a single-row "catalog overview" for the platform's daily dashboard. Schema: Track ColumnType TrackIdINTEGER...
Collapse many rows into one summary row per group.
Aggregation collapses many rows into one summary row per group: GROUP BY names the grouping columns, and SUM, COUNT, AVG, MIN and MAX describe each group. HAVING then filters the groups themselves, which is why it can reference an aggregate while WHERE cannot. This is the largest topic in the question bank because almost every analyst task, from revenue by month to active users per plan, is an aggregation with the right grouping key.
Generate a single-row "catalog overview" for the platform's daily dashboard. Schema: Track ColumnType TrackIdINTEGER...
The finance team needs revenue + invoice count per country for a target list of markets during the 2012–2013 fiscal...
The recommendation team wants a leaderboard of the most prolific artists measured by total tracks across all their...
Editorial wants a track-length profile per genre, restricted to genres with a meaningful catalog so single-track...
Loyalty wants every customer bucketed by total lifetime spend so they can target perks. Schema: Customer ColumnType...
HR is reviewing how customers are distributed across Sales Support Agents. Schema: Employee ColumnType...
Finance wants genre-level revenue from actual sales (not list prices), aggregated across all time. Schema: InvoiceLine...
Report the month-by-month invoice activity for fiscal year 2012. Schema: Invoice ColumnType InvoiceIdINTEGER (PK)...
Show customer buying activity per billing country: how many distinct customers bought, and the first/last invoice dates...
Identify managers and how many direct reports each has by self-joining the Employee table on ReportsTo. Schema:...
Identify the chunkiest albums — those with the most tracks. Show some shape metrics alongside. Schema: Album ColumnType...
Find customers who have purchased across multiple calendar years — a proxy for loyalty. Schema: Customer ColumnType...
Find customers whose most recent invoice falls on or before 2013-06-30. The retention team will reach out. Schema:...
Find genres whose average track price exceeds the overall catalog average. Schema: Track ColumnType TrackIdINTEGER (PK)...
Split invoice-line revenue into standard (UnitPrice = 0.99) vs premium (UnitPrice = 1.99) per billing country. Schema:...
FAQ
Short answers to what people get stuck on most. Tap a question to expand it.
WHERE filters rows before grouping. HAVING filters groups after aggregation.
SELECT region, SUM(amount) AS total
FROM orders
WHERE status = 'paid' -- row filter, before grouping
GROUP BY region
HAVING SUM(amount) > 1000; -- group filter, after groupingThey count different things: all rows, non-NULL values, or unique non-NULL values.
SELECT COUNT(*) AS order_rows,
COUNT(coupon_code) AS orders_with_coupon,
COUNT(DISTINCT user_id) AS unique_customers
FROM orders;Every selected column must be in GROUP BY or inside an aggregate, because the database cannot pick one value for the whole group.
-- error: name is neither grouped nor aggregated
SELECT customer_id, name, SUM(amount) FROM sales GROUP BY customer_id;
-- fix: group by it as well
SELECT customer_id, name, SUM(amount) FROM sales GROUP BY customer_id, name;Track your streak & earn XP
Sign up free to unlock your progress dashboard, daily streaks, and leaderboard ranking.
10 role-based tests for Data Analysts, SQL Developers & Data Engineers with instant scorecards.