Customer Lifetime Value Tier
Loyalty wants every customer bucketed by total lifetime spend so they can target perks. Schema: Customer ColumnType...
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...
The catalog team needs to identify dead inventory — tracks that have never appeared on any invoice. Schema: Track...
Finance wants genre-level revenue from actual sales (not list prices), aggregated across all time. Schema: InvoiceLine...
Identify the chunkiest albums — those with the most tracks. Show some shape metrics alongside. Schema: Album ColumnType...
For each country with customers, identify the top 3 spenders using a window function. Schema: Customer ColumnType...
Find customers whose most recent invoice falls on or before 2013-06-30. The retention team will reach out. Schema:...
Split invoice-line revenue into standard (UnitPrice = 0.99) vs premium (UnitPrice = 1.99) per billing country. Schema:...
Identify playlists with the broadest genre diversity for the "Discover" carousel. Schema: Playlist ColumnType...
Show quarter-by-quarter revenue per genre across calendar years 2012 and 2013 for the four largest genres. Schema:...
Show how many customers made their first-ever purchase each month — the new-customer cohort series. Schema: Invoice...
For each genre, find the top 3 tracks by units sold. Schema: InvoiceLine ColumnType InvoiceLineIdINTEGER (PK)...
For each manager, compute the total sales their entire organizational subtree generated (the manager's direct reports,...
Pivot revenue per billing country across days of the week — useful for spotting weekend-heavy markets. Schema: Invoice...
Using a CTE, first compute each customer's total spending (sum of their invoice totals). Then, from that CTE, return...
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.
Combine rows from two or more tables by matching a shared key.
A join combines rows from two or more tables by matching values in a shared key column. INNER JOIN keeps only the rows that match on both sides, LEFT JOIN keeps every row from the left table and fills the missing columns with NULL, and an anti-join finds rows with no match at all by adding WHERE right.id IS NULL. These questions cover the join shapes that actually show up in analytics work: fact-to-dimension lookups, self-joins over a hierarchy, and three- and four-table chains.
FAQ
Short answers to what people get stuck on most. Tap a question to expand it.
INNER JOIN keeps only rows that match in both tables. LEFT JOIN keeps every row from the left table, with NULLs where the right table has no match.
SELECT c.name, o.id AS order_id
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id;
-- customers with no orders show order_id = NULLUse an anti-join: keep the rows from table A that have no partner in table B.
A filter on the right table in WHERE removes the NULL rows a LEFT JOIN creates, so it behaves like an INNER JOIN.
SELECT c.name
FROM customers c
WHERE NOT EXISTS (
SELECT 1 FROM orders o WHERE o.customer_id = c.id
);-- keeps every customer, even those with no order over 100
SELECT c.name, o.amount
FROM customers c
LEFT JOIN orders o
ON o.customer_id = c.id AND o.amount > 100;