Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Retention Query for AR Lenses
00:00
5 left

Retention Query for AR Lenses

MediumSQL · PostgreSQL

Problem

Write a SQL query to calculate the month-over-month retention rate of users who interacted with an AR lens on Snapchat.

Assume retention for a month means the percentage of users active in the previous month who were also active in the current month. Include only valid users and lenses identified as AR lenses.

Output

  1. One row per month with a previous month of AR lens activity
  2. Columns: month, active_users, retained_users, and retention_rate
  3. active_users is the prior month's user count, and retained_users is the count active in both months
  4. Return retention_rate as a percentage rounded to two decimals, ordered chronologically

Schema

users
ColumnTypeDescription
user_idPKINTUnique Snapchat user identifier
usernameVARCHAR(50)User handle
platformVARCHAR(20)Primary mobile platform
signup_dateDATEDate the user registered
lenses
ColumnTypeDescription
lens_idPKINTUnique lens identifier
lens_nameVARCHAR(100)Display name of the lens
lens_typeVARCHAR(30)Lens classification
is_ar_lensBOOLEANWhether the lens is an AR lens
lens_interactions
ColumnTypeDescription
interaction_idPKINTUnique interaction identifier
user_idINTUser who interacted with the lens
lens_idINTLens used during the interaction
interacted_atTIMESTAMPTimestamp of the lens interaction
session_idVARCHAR(40)Optional Snapchat session identifier
Tablesuserslenseslens_interactions
Interviewer

Your question is Retention Query for AR Lenses. Start with the requirements and the three tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.