Products Sold Only in Q1 2019
Find the IDs of products that were sold only during the first quarter of 2019, from January 1 through March 31, inclusive. Exclude any product that has at least one sale outside the range 2019-01-01..
These ClickHouse SQL exercises focus on the kinds of data used in analytics: user events, purchases, logs, timestamps, and arrays. Practice calculating metrics, grouping events into time intervals, and using ClickHouse-specific functions alongside window functions. Your SQL runs in a real ClickHouse database and is automatically checked using hidden data. Problems: 535, free: 153.
Problems in this set: 535, free: 153
Start with a free problemProblems found: 382
Reset filtersFind the IDs of products that were sold only during the first quarter of 2019, from January 1 through March 31, inclusive. Exclude any product that has at least one sale outside the range 2019-01-01..
The marketing team is evaluating ad campaign performance. For each ad_id, calculate CTR using 100 * clicks / (clicks + views).
The product team is building a histogram of user engagement. Session durations are stored in seconds. Group sessions into these minute-based duration bins: [0-5>, [5-10>, [10-15>, 15 or more.
Find managers with at least five direct reports. Return their names.
A brokerage is preparing a trading performance report. For each stock (stock_name), calculate the financial result as the sum of sales (operation = 'Sell') minus the sum of purchases (operation =…
Before meeting with RED, management wants to identify salespeople who have never handled an order from that company. Return those salespeople's names.
A marketplace needs to identify the sellers with the most revenue.
Samsung's marketing team is looking for customers who stay within the brand's ecosystem: they bought an S8 but never bought an iPhone. Find these buyers and return their buyer_id.
An analyst is comparing apple and orange sales over time. For each date, return sale_date and the difference between the number of apples sold (fruit = 'apples') and the number of oranges sold (fruit…
A brokerage firm is preparing a report on portfolio trading results.
A travel service is creating a leaderboard based on users' total travel distances. For each user, return their name and the sum of the distances of all their rides as travelled_distance.
A bookstore is clearing slow-selling books from its catalog. Assume today is 2019-06-23.
arrayJoin expands array elements into separate rows. One original event can therefore become several rows, changing subsequent counts and sums. If you need to count original events rather than array elements, check how the transformation affects the data, including events with empty arrays.
ClickHouse's uniq function returns an approximate number of distinct values. That may be appropriate for analytics, but it is not interchangeable with an exact count when precision matters. Check the problem's requirements before selecting a distinct-counting function.
argMax returns a value associated with the maximum of another expression. If several rows share that maximum, the selected value may not be deterministic. Consider whether tied timestamps or amounts are possible and whether the problem needs an additional way to choose between them.
Functions such as toStartOfHour group timestamps by interval boundaries. If the expected reporting timezone differs from the timestamp interpretation, events can land in the wrong hour or day. Inspect records near interval boundaries, especially around midnight, to catch these mistakes.
Yes. Every query executes in a real ClickHouse database, and its result is automatically checked against expected output using hidden data. The exercises cover event aggregation, arrays, time-based analysis, and window functions, so you can practice both syntax and analytical reasoning.
Yes. Free problems in this collection: 153. Once signed in, you can solve up to 3 new problems per day on the free plan. Premium problems are visible but require a subscription. Hints and an AI mentor are available in the problems.
arrayJoin expands the elements of an array into separate rows. This is useful when an event contains a list of products or other values that must be analyzed individually. Because it changes row counts, decide whether your later calculations should count original events or expanded elements.
Use countIf when you need to count rows that meet a condition, and sumIf when you need to sum values only for matching rows. Both are useful for event analytics, such as calculating views and purchases separately within the same grouping. Check which records qualify for each metric.
MergeTree is a family of ClickHouse table engines that matters when studying data storage and query performance. You do not need to understand every storage detail before practicing basic analytical queries. Start with selections and aggregates, then explore table engines as the problems become more advanced.