KatInterview

Video Call Metrics: Regional Reach and Per-User Talk Time

SQL & DataModel answer
MediumModel answerSQL & Datasqljoinsaggregation

Last updated

Write two SQL queries over daily call and profile tables: the share of French users on a call yesterday, and total U.S. call time divided by the number of U.S. daily-active users today.

Context

A video-calling product tracks how engaged its users are. You have two tables that are partitioned by day.

call_logs: one row per call.

columnmeaning
callerID of the user who started the call
recipientID of the user who received the call
dsdate of the call
call_ididentifier of the call
durationlength of the call (float, in seconds)

user_profile: one daily snapshot row per user.

columnmeaning
user_iduser identifier
age_bucketage group, e.g. 25-34
countrycountry, e.g. US, FR
primary_ose.g. iOS, Android
dau_flag1 if the user was a daily active user that day, otherwise 0
dsdate of the snapshot

Sample rows:

call_logs                                          user_profile
caller recipient ds         call_id duration       user_id age_bucket country primary_os dau_flag ds
123    456       2019-01-01 4325    864.4          123     25-34      US      iOS        1        2019-01-01
032    789       2019-01-01 9395    263.7          456     35-44      FR      Android    1        2019-01-01
456    032       2019-01-01 0879    22.0           789     18-24      FR      iOS        0        2019-01-01

Tasks

  1. Write a query that returns the percentage of French users who made or received at least one call yesterday.
  2. Write a query that returns today's total call time divided by the number of U.S. daily-active users (users with dau_flag = 1).

What to address

  • State your assumptions about how the country is stored (the sample uses codes such as FR, not full names).
  • Make sure no user and no call is counted twice.
  • Decide what happens for users with no calls and for days with no data.
  • Explain why each numerator and denominator is right.

Hints

Hint 1

Both answers are ratios, so decide the numerator and denominator separately. For the first query, the denominator is every French user in yesterday's snapshot, including those who never called.

Hint 2

A user can appear as a caller, as a recipient, or both, and many times. Stack the two columns into a single list of distinct user IDs (UNION rather than UNION ALL) and then match it against the French users. Remember that the profile table has one row per user per day, so filter it to a single date.

Hint 3

For the second query, a call between two U.S. DAU must contribute its duration only once. Reduce to one row per call that has at least one U.S. DAU participant, sum the durations, and divide by a separately computed count of U.S. DAU, so that users without calls still count in the denominator.