Posts Reported on July 4, 2024
A social media moderation team is analyzing reports received on a single day. Each row in Actions represents a user's action on a post: view, like, repost, report, or delete.
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 problemA social media moderation team is analyzing reports received on a single day. Each row in Actions represents a user's action on a post: view, like, repost, report, or delete.
Count the followers of each user. Return user_id and followers_count. Sort the result by user_id in ascending order.
The academic administration wants to know which classes have enrolled enough students to start classes. Find all classes with 5 or more students. Return the class column.
A casting agency is looking for established actor-director partnerships. Return the actor_id and director_id for each actor-director pair that has worked together at least 3 times.
The bank is preparing a report on users with high account balances. An account's balance is the sum of all transactions for that account. Find users whose total account balance exceeds 10000.
The sales team is analyzing daily activity by car make. For each date (date_id) and make (make_name), count the number of distinct leads (unique_leads) and distinct partners (unique_partners).
The HR team is compiling employee work hours. An employee may enter and leave the office multiple times in a single day, so you need to add up all their time intervals in the office.
The security team is reviewing user activity in 2020. For each user who logged in at least once in 2020, find the timestamp of their last login during that year. Return user_id and last_stamp.
The academic office is reviewing students' workloads to find those studying several subjects. Each row in StudyPatterns represents one study session, recording a student, a subject, and a date.
You're a data analyst at Bramble Market, a chain of neighborhood convenience stores.
You're a product analyst at Wavelane, a music streaming service. The growth team wants monthly engagement figures: how many plays users started and how many total hours of music they listened to.
You're a data analyst for a convenience store chain. The operations director is preparing a weekly summary of online orders and wants to see how many orders each store received, how many were…
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.