The part that slowed me down was joining Users twice, once for the caller and once for the receiver.
Start by clarifying the schema and the definition of 'last 30 days' (e.g., relative to current date or a fixed date). Then write a query that joins the Calls table to the Users table twice (once for caller, once for receiver) to get country information, filters calls to the last 30 days, groups by caller country and receiver country, and computes COUNT(*) and AVG(duration).
Pro tip: Mention that you would check for data quality issues like null durations or missing country info, and consider whether to use INNER JOIN or LEFT JOIN based on whether you want to include calls with unknown users. Also, discuss the trade-off between using a subquery to filter recent calls first versus filtering after the join for performance.
Ask about the table structures, column names, and how 'last 30 days' is defined (e.g., based on call start time). Confirm whether to include calls with missing user info.
Use a WHERE clause on the Calls table to restrict to calls within the last 30 days, e.g., call_date >= CURRENT_DATE - INTERVAL '30 days'.
Join Calls to Users twice: once on caller_id = Users.user_id to get caller_country, and once on receiver_id = Users.user_id to get receiver_country.
Group by caller_country and receiver_country, then compute COUNT(*) as total_calls and AVG(duration) as avg_duration.
Discuss handling of NULLs, potential duplicate calls, and indexing strategies to optimize the query.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.