Snapchat
Interview Core Track · Medium · 25 min
02 Sending Vs Opening Snaps
-- Assume you're given tables with information on Snapchat users, including their ages and time spent sending and opening snaps. -- Write a query to obtain a...
Company labels are directional practice context, not official interview guidance.
Objective
Practice aggregation through a Snapchat-tagged business scenario.
Approach
Use this track to improve speed, edge-case handling, and accuracy under timed conditions.
Company context
Company labels are directional practice context, not official interview guidance.
-- Assume you're given tables with information on Snapchat users, including their ages and time spent sending and opening snaps. -- Write a query to obtain a breakdown of the time spent sending vs. opening snaps as a percentage of total time spent on these activities grouped by age group. Round the percentage to 2 decimal places in the output. -- Notes: -- - Calculate the following percentages: -- - time spent sending / (Time spent sending + Time spent opening) -- - Time spent opening / (Time spent sending + Time spent opening) -- - To avoid integer division in percentages, multiply by 100.0 and not 100. SELECT age_bucket, round(100.0 * Sum(a.time_spent) filter(WHERE activity_type='send') / sum(a.time_spent), 2) AS send_perc, round(100.0 * sum(a.time_spent) filter(WHERE activity_type='open') / sum(a.time_spent), 2) AS open_perc FROM activities a JOIN age_breakdown ab using (user_id) WHERE a.activity_type IN('send', 'open') GROUP BY 1 -- remarks: didn't think of this: WHERE a.activity_type IN('send', 'open')
activities
age_breakdown
SQL workspace
Run queries against the protected question data, then submit once the result shape looks right.
Sign in to run SQL
Create a free account or sign in before running queries against protected question data.