Users with Multiple Orders
The marketing team wants to find users who have placed more than one order and might qualify for a loyalty program.
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 filtersThe marketing team wants to find users who have placed more than one order and might qualify for a loyalty program.
Avito's finance team is calculating monthly payroll for contact center employees. Hourly rates can change within a month, so use the rate in effect on each workday.
At SberMarket, a product analyst is calculating a retention metric called average time between orders. The metric is used for triggered push notifications and win-back campaigns.
VTB's CRM analytics team is building a quarterly client leaderboard for its rewards program. Include only non-refund transactions (is_refund = FALSE) in transaction volume.
Vizor buys mobile traffic through ad networks and compares performance by country.
The HR system is identifying incomplete records so the team can correct the employee directory.
To check driver schedules, the tour coordinator needs a list of tour departures that left on January 15, 2024, between 10:00 and 14:00, inclusive of both times.
The security team is cleaning up logs and looking for IP addresses with an invalid format. Find IP addresses that do not match the IPv4 pattern X.X.X.X, with 1–3 digits in each octet. Return ip.
The band's loyalty program is ranking superfans by the number of concerts they have attended.
A book club wants to identify its most active readers in 2005 by their total borrowing expenses. For each club member, calculate the total cost of books they borrowed that year.
A lab is examining DNA sequences for the start codon ATG. Find the samples containing it and return sample_id, the sequence (dna_sequence), and start_pos—the position of the first occurrence of ATG…
Twitter is building a histogram of user activity for 2022. Group users by how many tweets they posted that year, using that number as tweet_bucket.
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.