Search ⌘K
S
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...

Interview Core Track
Medium
25 min
aggregation
joins
filtering

Company labels are directional practice context, not official interview guidance.

Timer 00:00
Back to practice

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.

Prereq: query basics
Prereq: filtering

-- 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
activity_id INTEGER PRIMARY KEY
user_id INTEGER NOT NULL
activity_type VARCHAR(10
age_breakdown
user_id INTEGER PRIMARY KEY
age_bucket VARCHAR(10
Editor
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.