Week Over Week Ad Revenue by Country With a Full Outer Join

Last updated: November 29, 2026

Quick Overview

Compare this week's and last week's Meta ad revenue by advertiser country, including countries that appear in only one of the two weeks, and label each country as new, lost, growing, or shrinking.

Meta
Data Manipulation (SQL/Python)
Data Scientist
Meta
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Compare this week's and last week's Meta ad revenue by advertiser country, including countries that appear in only one of the two weeks, and label each country as new, lost, growing, or shrinking.

Weekly business reviews in Meta's ads org lean on period-over-period tables, and this question checks a FULL OUTER JOIN between two aggregates. The interviewer looks for COALESCE on keys and values and safe percent change math.

What the Interviewer Expects
  • Aggregates each week separately before joining
  • Uses FULL OUTER JOIN so one-sided countries survive
  • COALESCEs the country key and the revenue values
  • Guards percent change against division by zero
  • Labels new and lost countries explicitly
Key Topics to Cover
FULL OUTER JOIN
COALESCE
period over period
NULLIF
ads revenue
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you do this with conditional aggregation and no join at all?
  • How would you add a minimum revenue threshold to avoid noisy labels?
  • How would you handle currency changes over the two weeks?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

ad_revenue(advertiser_id, country, rev_date, revenue_usd), one row per advertiser per day. "This week" is the last seven complete days, "last week" the seven before. Country is the advertiser's bill...

Approach

Build two aggregates, one per week, at country grain. FULL OUTER JOIN them on country. A LEFT JOIN from this week would drop countries that went to zero, which are often the most interesting rows. The...


Submit Your Answer
Markdown supported