The Create a Session Bar Chart interview question is a SQL-based data reporting task. You are given a table of user sessions with their durations. You need to group these sessions into four specific duration buckets: [0-5), [5-10), [10-15), and 15 or more minutes. For each bucket, you must report the total number of sessions.
Twitch and other streaming platforms use this database interview pattern to test a candidate's ability to generate custom aggregates. It requires moving beyond simple GROUP BY operations on existing columns and instead creating "virtual" groups using conditional logic. It evaluates proficiency with CASE WHEN statements and the ability to ensure all categories appear in the final output, even if they have zero counts.
This problem uses Conditional Aggregation and Static Row Generation.
CASE WHEN statement to label each session duration into one of the four categories.GROUP BY would omit categories with zero sessions, you should either:
LEFT JOIN it with the grouped session data.UNION statements to ensure every bucket is present.Session Durations: 2, 4, 7, 20
[0-5). Count = 2.[5-10). Count = 1.[10-15). Count = 0.15 or more. Count = 1.
Final table shows all 4 categories with their counts 2, 1, 0, 1.GROUP BY which results in the [10-15) bucket being missing entirely from the result instead of showing 0.BETWEEN 5 AND 10 which includes 10 in two buckets).Master the "Static Table + Left Join" trick in SQL. It's the standard way to ensure that your reports include rows for categories that have no data in the underlying tables.