The join structure took me a second to get right.
First, clarify the schema and definitions: identify the ads table with creation source, impressions table with ad_id and date, and revenue events table with ad_id, date, and revenue. Then, compute daily active ads by joining impressions to ads and grouping by date and source, and finally join revenue events to these active ads on the same day to sum revenue and count distinct active ads.
Pro tip: Explicitly state your assumptions about the schema (e.g., column names, date fields) and edge cases (e.g., multiple impressions per ad per day, revenue events without impressions) before writing the query—this shows you think like a data scientist who validates data before analysis.
Ask or state assumptions about table structures: ads (ad_id, creation_source), impressions (ad_id, impression_date), revenue_events (ad_id, revenue_date, revenue_amount). Define 'active ad' as having at least one impression on that day.
Write a subquery or CTE that selects distinct ad_id and date from impressions, then join to ads to get creation_source. This yields one row per active ad per day per source.
Group the active ads by date and creation_source to count distinct active ads per day per source.
Join revenue_events to the active ads on both ad_id and date (revenue_date = impression_date), then sum revenue per day per source. Ensure only revenue for active ads on that same day is included.
Combine the active ad count and revenue sum into a final query, grouping by date and source, and order by date and source ascending.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.