The tie-breaking part is where I almost slipped up.
Start by clarifying the schema and definitions, then write a SQL query that filters calls to the last 7 days, excludes self-calls, and aggregates by caller_id to compute distinct recipients and total calls. Finally, rank the results using the specified tie-breaking rules and limit to the top 10.
Pro tip: Explicitly state your assumptions about the date range (e.g., last 7 days from today) and whether 'distinct recipients' counts unique recipient IDs per caller. Also, mention that you would validate the results by checking edge cases like callers with only self-calls or ties.
Confirm the table structure, date range definition, and what constitutes a 'call' (e.g., any row in video_calls). Ask if there are any additional filters like call status.
Write a subquery or CTE to filter calls from the last 7 days and exclude self-calls (caller_id != recipient_id). Then group by caller_id to compute COUNT(DISTINCT recipient_id) and COUNT(*).
Use a window function or ORDER BY with the specified tie-breaking rules: ORDER BY distinct_recipients DESC, total_calls DESC, caller_id ASC. Limit to 10 rows.
Mention potential edge cases: callers with no calls in the period, ties beyond the top 10, and how the query handles them. Suggest validating with sample data.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
This one got me for a second because of the union approach.
First, filter the daily_users table to active French users on the given date to get the denominator. Then, identify distinct users who were either caller or recipient in video_calls on that same date, and intersect with the active French users to get the numerator. Finally, compute the percentage as numerator divided by denominator times 100.
Pro tip: Clarify whether 'active French users' means users with dau_flag=1 and country='France' on that date, and ensure you handle potential duplicates in video_calls by using DISTINCT on user IDs. Also, consider timezone alignment between the daily_users date and video_calls timestamp.
Filter the daily_users table for the specific date where dau_flag = 1 and country = 'France'. This set forms the denominator.
From video_calls on the same date, extract distinct user IDs from both caller and recipient columns. Union these to get all users who participated in at least one call.
Join the active French users with the call participants to find those who appeared in at least one call. Count distinct users for the numerator.
Compute the percentage as (numerator / denominator) * 100. Return numerator, denominator, and percentage.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.