Which Marketplace Customers Need to Be Re-engaged?
You're a product analyst at a B2B marketplace. The CRM team is preparing a customer win-back campaign and wants to know how many calendar days have passed since each active buyer's most recent…
Turn individual records into useful metrics with SQL aggregate functions practice. Count events, calculate totals and averages, group results by users or products, and filter groups based on their values. Your SQL runs in a real database, with results automatically checked against hidden data. Problems in this set: 266, free: 70.
Problems in this set: 266, free: 70
Start with a free problemYou're a product analyst at a B2B marketplace. The CRM team is preparing a customer win-back campaign and wants to know how many calendar days have passed since each active buyer's most recent…
You're analyzing monetization for an audiobook app. The subscription team wants to compare all listeners by their number of completed purchases in the second quarter of 2026, including listeners who…
You're a data quality analyst at a last-mile delivery platform. Warehouses upload parcel registrations in batches, and resubmitting a file sometimes creates multiple rows for the same parcel.
You're a product analyst at a fintech startup that opens digital accounts for small businesses.
You're a product analyst at Northstar, a mobile bank. The onboarding team wants to know when each customer first used the app. This will help compare customer activation speed across future campaigns.
L. is preparing a city-level summary to see where payments were recorded most often.
QUERY is comparing platforms before reconstructing Kotomarket’s old funnel.
L. is checking how product interest turned into purchases across different cities. For each city, separately count product_view and purchase events, using a condition-based counter for each metric.
After the outage, QUERY checks whether the checkout came back to life at least once on each platform. For each platform, output platform and had_purchase: true if at least one of its events was paid.
L. is looking for the hours when the Kotomarket archive is most active. Group the events by the hour from event_ts and return the hour number as hour and the event count as cnt. Sort by hour.
From the events table (columns user_id, event_type), for each user_id count views (number of 'view' events) and purchases (number of 'purchase' events).
From the events table (columns product_id, event_type), count for each product_id the number of 'view' events and 'purchase' events. Return product_id, views, purchases. Sort by product_id ascending.
Adding an unnecessary column to GROUP BY can split one expected group into several. Leaving out a required column can combine unrelated records. Define what one output row should represent, such as a user, product, day, or combination of dimensions, before building the aggregation.
COUNT(*) counts rows, while COUNT(column) ignores rows where that column is NULL. The difference matters whenever data is missing. Compare the counts on a small sample and decide whether the task requires every record or only records with a non-NULL value.
WHERE filters individual rows before aggregation. HAVING filters groups after aggregate values have been calculated. If you need products with a minimum number of purchases, removing rows too early can change the result. Separate conditions on source records from conditions on grouped metrics.
A JOIN can multiply records before aggregation. For example, an order may appear several times when joined to a table containing multiple related entries. That can inflate totals without producing an obvious error. Check the join keys and the number of underlying records being counted.
Your SQL executes in a real database, and the resulting data is automatically compared with an expected result using hidden data. A correct query must handle more than the obvious cases, including missing values, repeated records, and groups of different sizes.
Yes. Free problems in this collection: 70. Once signed in, you can solve up to 3 new problems per day on the free plan. Premium problems are listed alongside them, but solving those requires a subscription.
Use WHERE for conditions on individual records before grouping, such as restricting events to a particular date range. Use HAVING when the condition depends on an aggregate result, such as total sales. A single query can use both to filter source data and then filter groups.
You may be counting events when the problem asks for unique users or orders. Duplicate records and joins can also increase the total. Check what each row represents and whether NULL values matter. Match the counting method to the exact entity described in the question.
GROUP BY combines source rows into aggregated results, typically one row per group. Window functions calculate values across related rows without necessarily collapsing the original rows. Choose GROUP BY when you need a summary and window functions when individual records must remain visible.