SQL data engineering interview problem. Difficulty: intermediate. Pattern: Aggregation. About 15 minutes. Part of the Pro drill bank.
social_users lists every user and comments lists comments with a created_at date. Build a histogram of January 2026 activity: for each possible number of comments comment_count, from 0 up to the highest count any user reached, return user_count, the number of users who wrote exactly that many comments in January 2026 (1 Jan to 31 Jan inclusive). Counts with no users still appear with user_count 0. Users with no comments at all are counted in bucket 0. Columns: comment_count, user_count. Order by comment_count.
Input: social_users user_id 1 2 3 4 5 6 7 8 comments comment_id | user_id | created_at 1 | 1 | 2025-12-30 2 | 3 | 2026-01-05 3 | 4 | 2026-01-06 4 | 5 | 2026-01-07 5 | 5 | 2026-02-01 6 | 6 | 2026-01-08 7 | 6 | 2026-01-09 8 | 7 | 2026-01-10 9 | 7 | 2026-01-11 10 | 7 | 2026-01-12 11 | 7 | 2026-01-13 12 | 8 | 2026-01-14 ... Output: comment_count | user_count 0 | 2 1 | 3 2 | 2 3 | 0 4 | 1 Why this passes: Users 1 and 2 have no January comments (bucket 0). Users 3, 4 and 5 have one (user 5's February comment is ignored). Users 6 and 8 have two. User 7 has four. Nobody has three.
Input: social_users user_id 1 2 comments comment_id | user_id | created_at 1 | 1 | 2026-01-10 Output: comment_count | user_count 0 | 1 1 | 1 Why this passes: Two users, one with a comment.
Topics: lakebench, sql, histogram, left join, zero buckets.
More SQL interview questions · All interview problems · Learn data engineering
Interview-style drill: How many users wrote 0, 1, 2, ... comments in January 2026, including users who wrote none.
`social_users` lists every user and `comments` lists comments with a `created_at` date. Build a histogram of January 2026 activity: for each possible number of comments `comment_count`, from 0 up to the highest count any user reached, return `user_count`, the number of users who wrote exactly that many comments in January 2026 (1 Jan to 31 Jan inclusive). Counts with no users still appear with `user_count` 0. Users with no comments at all are counted in bucket 0. Columns: `comment_count`, `user_count`. Order by `comment_count`.