Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Count Users Involved in Calls

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Count Users Involved in Calls. Start with the requirements and the two tables on the right.

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.

Problem

Meta’s calling team wants to measure how many unique users participated in calls on each day, broken out by age bucket and daily active status. A user should be counted if they appear as either the caller or the recipient in the calls table.

Write a PostgreSQL query to return the number of distinct users involved in calls for each date, age_bucket, and daily_active_flag.

Requirements

  1. Count a user once per day even if they appear in multiple calls.
  2. Treat a user as involved if they are either the caller or the recipient.
  3. Join call participants to the demographic snapshot for the same date.
  4. Return results ordered by date, age_bucket, then daily_active_flag.

Schema

calls
ColumnTypeDescription
call_idPKINTUnique call identifier
callerBIGINTUser ID of the caller
recipientBIGINTUser ID of the recipient
dateDATECall date
durationINTCall duration in seconds
user_demographics
ColumnTypeDescription
user_idBIGINTMeta user ID
age_bucketVARCHAR(20)Age segment for the user
daily_active_flagBOOLEANWhether the user was active on that date
dateDATEDemographic snapshot date
Tablescallsuser_demographics
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results