KatInterview

Weekly Top Dialers and Share of French Video Participants

SQL & DataModel answer
MediumModel answerSQL & Datasqlaggregationdate-filtering

Last updated

Write two SQL queries on a call-log table: rank the ten users who placed the most calls in the past week, and compute the share of yesterday's French users who joined a video call.

A messaging app stores one row per call in a table named calls:

call_idcaller_idreceiver_idcall_start_timecountrycall_type
11012022023-10-10 09:05:00Francevideo
21032042023-10-10 10:15:00Indiavoice
31011052023-10-09 22:30:00Francevideo
41061072023-10-03 05:45:00Brazilvideo
51081092023-10-10 13:20:00Francevoice

call_start_time is a timestamp, country is the country in which the call took place, and call_type is either video or voice.

The product team wants two answers from this table.

Task 1. Return the 10 users who started the most calls (as caller_id) during the last 7 days, together with their call counts.

Task 2. Compute the percentage of active users in France who took part in a video call yesterday.

Before you write any SQL, state the assumptions you are making. In particular, address:

  • How you define the "last 7 days" window and whether today is included.
  • How you break ties at the 10th position.
  • What "active user" means, and whether a user who only received a call counts.
  • How you avoid integer division and division by zero.

Provide your queries, walk through the sample data (assume today is 2023-10-11), and mention any edge cases you would raise with the interviewer. A pandas version is a welcome bonus.

Hints

Hint 1

Use a half-open time range (`>= start AND < end`) rather than `BETWEEN` on a timestamp, so rows late in the final day are not lost or double counted.

Hint 2

For Task 1, filter to the window, `GROUP BY caller_id`, `COUNT(*)`, then order by the count descending with `caller_id` as a deterministic tie-breaker before applying `LIMIT 10`.

Hint 3

For Task 2, a user can be on either end of a call. Stack caller and receiver into one `user_id` column (`UNION ALL`), then use `COUNT(DISTINCT user_id)` for the denominator and `COUNT(DISTINCT CASE WHEN call_type = 'video' THEN user_id END)` for the numerator.

Hint 4

Multiply by `100.0` to force decimal arithmetic and wrap the denominator in `NULLIF(..., 0)` so a day with no French activity returns NULL rather than an error.