Compute High-Call Usage Rates
MetaData Scientist · Technical ScreenLast updated
This question evaluates a candidate's ability to perform advanced data manipulation and analytical SQL tasks, including joins, aggregations, timezone-aware date handling, rolling window metrics, distinct user counting, and counting user participations across roles.
You are given two tables for a voice-calling product:
users
user_idBIGINTcountry_codeSTRING
calls
call_idBIGINTcaller_idBIGINTrecipient_idBIGINTstarted_atTIMESTAMP
calls.caller_id and calls.recipient_id both reference users.user_id.
Assume:
- Every row in
callsis one valid call event. - All timestamps are stored in UTC.
- Any date-based metric should be computed in the
Europe/Londontimezone. report_dateis a calendar date inEurope/London.
Write SQL to compute the following metrics for each report_date:
- Percentage of callers with at least 20 calls in the last 7 days
- Use the 7-day window ending on
report_date, inclusive. - The numerator is the number of distinct users who initiated at least 20 calls in that 7-day window.
- The denominator is the number of distinct users who initiated at least 1 call in that same 7-day window.
- Percentage of Great Britain DAU with at least 50 total calls
- Restrict to users with
country_code = 'GB'. - Define daily active users as distinct GB users who either placed or received at least one call on
report_date. - For each such user, count total call participations on
report_date, where participations include both outgoing calls ascaller_idand incoming calls asrecipient_id. - The numerator is the number of GB DAU with at least 50 total call participations on
report_date. - The denominator is all GB DAU on
report_date.
Return one row per report_date with these columns:
report_datepct_callers_20plus_last_7dpct_gb_dau_50plus_calls
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.