cswork / libraryOpen practice workspace

Coding questions · Meta

Compute French DAU video-call percentage yesterday

This question evaluates the ability to perform data manipulation and metric computation across relational tables using SQL or Python, specifically measuring daily active users and video-call participation for a geographic subset.

Compute the percentage of daily active users (DAU) from France who were on at least one video call yesterday (2025-08-31 UTC). DAU is defined as users with any event on 2025-08-31 in events. A user is "from France" if users.country_code = 'FR'. A user counts as having a video call if they appeared as caller or callee in calls with media_type = 'video' and started_at on 2025-08-31 UTC. Return a single row with columns denom_dau_fr, numer_video_callers_fr, pct_video_callers_fr (as a decimal between 0 and 1).

Schemas:

  • users(user_id INT, country_code CHAR(2), created_at TIMESTAMP)
  • events(event_id INT, user_id INT, event_type TEXT, event_ts TIMESTAMP)
  • calls(call_id INT, caller_id INT, callee_id INT, started_at TIMESTAMP, media_type TEXT)

Sample rows (subsets):

users
+---------+--------------+
| user_id | country_code |
+---------+--------------+
| 1 | FR |
| 2 | FR |
| 3 | US |
| 4 | FR |
+---------+--------------+
events
+----------+---------+------------+---------------------+
| event_id | user_id | event_type | event_ts |
+----------+---------+------------+---------------------+
| 501 | 1 | app_open | 2025-08-31 10:00:00 |
| 502 | 2 | search | 2025-08-31 11:00:00 |
| 503 | 3 | app_open | 2025-08-31 12:00:00 |
| 504 | 4 | app_open | 2025-08-31 13:00:00 |
| 505 | 4 | like | 2025-08-30 14:00:00 |
+----------+---------+------------+---------------------+
calls
+---------+-----------+----------+---------------------+------------+
| call_id | caller_id | callee_id| started_at | media_type |
+---------+-----------+----------+---------------------+------------+
| 701 | 1 | 2 | 2025-08-31 15:00:00 | video |
| 702 | 2 | 1 | 2025-08-31 16:00:00 | audio |
| 703 | 4 | 3 | 2025-08-31 17:00:00 | video |
| 704 | 2 | 5 | 2025-09-01 09:00:00 | video |
+---------+-----------+----------+---------------------+------------+

Write a single SQL query; avoid hard-coding user_ids.

Compute French DAU Video Call Percentage on 2025-08-31

Using the tables below, compute the percentage of daily active users (DAU) from France who were on at least one video call on 2025-08-31 (UTC).

Definitions:

  • A user is "from France" if users.country_code = 'FR'.
  • DAU for 2025-08-31 is defined as users who have at least one event in events where event_ts is on 2025-08-31 (UTC), i.e., event_ts >= '2025-08-31 00:00:00' AND event_ts < '2025-09-01 00:00:00'.
  • A user counts as having a video call if they appeared as caller or callee in calls with media_type = 'video' and started_at on 2025-08-31 (UTC), i.e., started_at >= '2025-08-31 00:00:00' AND started_at < '2025-09-01 00:00:00'.

Task: Return a single row with the following columns:

  • denom_dau_fr: number of French DAU on 2025-08-31.
  • numer_video_callers_fr: number of those French DAU who were on at least one video call on 2025-08-31.
  • pct_video_callers_fr: numer_video_callers_fr divided by denom_dau_fr as a decimal between 0 and 1. If there are no French DAU, return 0 for the percentage.

Write a single SQL query to produce this result. Do not hard-code any user_ids.

Table users

columntypeconstraints
user_idINTPRIMARY KEY, NOT NULL
country_codeCHAR(2)NOT NULL
created_atTIMESTAMPNOT NULL

Sample data:

country_codecreated_atuser_id
FR2025-01-10 09:00:001
FR2025-02-15 10:30:002
US2025-03-20 12:00:003
FR2025-04-05 08:45:004
DE2025-05-01 14:15:005

Table events

columntypeconstraints
event_idINTPRIMARY KEY, NOT NULL
user_idINTNOT NULL
event_typeVARCHAR(50)NOT NULL
event_tsTIMESTAMPNOT NULL

Sample data:

event_idevent_tsevent_typeuser_id
5012025-08-31 10:00:00app_open1
5022025-08-31 11:00:00search2
5032025-08-31 12:00:00app_open3
5042025-08-31 13:00:00app_open4
5052025-08-30 14:00:00like4
5062025-08-29 09:00:00app_open5

Table calls

columntypeconstraints
call_idINTPRIMARY KEY, NOT NULL
caller_idINTNOT NULL
callee_idINTNOT NULL
started_atTIMESTAMPNOT NULL
media_typeVARCHAR(20)NOT NULL

Sample data:

call_idcallee_idcaller_idmedia_typestarted_at
70121video2025-08-31 15:00:00
70212audio2025-08-31 16:00:00
70334video2025-08-31 17:00:00
70452video2025-09-01 09:00:00

Expected output

A single-row result showing: (1) the number of French DAU on 2025-08-31, (2) how many of those French DAU participated in at least one video call on that date, and (3) the resulting fraction as a decimal between 0 and 1.

denom_dau_frnumer_video_callers_frpct_video_callers_fr
331

Hints

  1. First find French users who are DAU on 2025-08-31 using the events table and users.country_code = 'FR'.
  2. Unpivot the calls table so that both caller_id and callee_id become user_id, filter to video calls on 2025-08-31, then intersect with the French DAU set and compute the ratio.