cswork / libraryOpen practice workspace

Coding questions · Meta

Analyze Group Call Adoption Using SQL Queries

This question evaluates SQL data-manipulation and analytical skills, including aggregation, conditional counting, distinct counts, date-based grouping, and percentage calculations on event logs.

CALL_LOGS

| call_id | user_id | call_start           | call_end             | is_group_call | participant_cnt |
| 101     | 12      | 2023-08-01 10:00:00  | 2023-08-01 10:15:00  | 0             | 2               |
| 102     | 34      | 2023-08-01 10:05:00  | 2023-08-01 10:30:00  | 1             | 4               |
| 103     | 56      | 2023-08-01 11:00:00  | 2023-08-01 11:20:00  | 1             | 3               |
| 104     | 12      | 2023-08-02 09:00:00  | 2023-08-02 09:10:00  | 0             | 2               |
| 105     | 78      | 2023-08-02 09:15:00  | 2023-08-02 09:40:00  | 1             | 5               |
Scenario

A messaging app is launching a new "group call" feature. You have access to historical call data and need to quantify early adoption of the feature.

Question

Using the call_logs table, write SQL to:

For each calendar day, return (a) total calls, (b) total group calls, (c) unique callers who initiated a group call, and (d) percentage of calls that are group calls.

List all days where group-call percentage is below 10%.

Hints

DATE(call_start), COUNT(*), SUM(is_group_call), COUNT(DISTINCT CASE WHEN is_group_call=1 THEN user_id END)

Daily Group Call Adoption Metrics

Table CALL_LOGS

columntypeconstraints
call_idINTEGERPRIMARY KEY, NOT NULL
user_idINTEGERNOT NULL
call_startTIMESTAMPNOT NULL
call_endTIMESTAMPNOT NULL
is_group_callINTEGERNOT NULL, CHECK (is_group_call IN (0,1))
participant_cntINTEGERNOT NULL, CHECK (participant_cnt >= 2)

Sample data:

call_endcall_idcall_startis_group_callparticipant_cntuser_id
2023-08-01 10:15:001012023-08-01 10:00:000212
2023-08-01 10:30:001022023-08-01 10:05:001434
2023-08-01 11:20:001032023-08-01 11:00:001356
2023-08-02 09:10:001042023-08-02 09:00:000212
2023-08-02 09:40:001052023-08-02 09:15:001578

Expected output

One row per day with call_date, total_calls, total_group_calls, unique_group_callers, and group_call_pct (0–100, rounded to 2 decimals), filtered to days where group_call_pct < 10. With the provided data: 2023-08-01 has 3 total calls and 2 group calls (66.67%); 2023-08-02 has 2 total calls and 1 group call (50.00%). No day is below 10%, so the result set is empty.

Hints

  1. Group by DATE(call_start) to aggregate per day.
  2. Use SUM(is_group_call) to count group calls if is_group_call is 0/1.
  3. Use COUNT(DISTINCT CASE WHEN is_group_call = 1 THEN user_id END) for unique group callers.
  4. Compute the percentage as SUM(is_group_call) * 100.0 / COUNT(*), then filter by < 10.