Compute eCPM by Ad Network and Country From Impression Logs

Last updated: November 29, 2026

Quick Overview

Given an impressions table with app, ad network, country and revenue per impression, write SQL that reports eCPM (revenue per thousand impressions) per ad network and country for the last 7 days, keeping only groups with at least 1,000 impressions.

Unity
Data Manipulation (SQL/Python)
Data Scientist
Unity
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Given an impressions table with app, ad network, country and revenue per impression, write SQL that reports eCPM (revenue per thousand impressions) per ad network and country for the last 7 days, keeping only groups with at least 1,000 impressions.

eCPM is the core metric behind Unity's LevelPlay mediation and Unity Ads dashboards, so analytics screens for the Grow business often start here. The interviewer checks that you compute a ratio of sums rather than an average of ratios and that you filter noisy small groups.

What the Interviewer Expects
  • Define eCPM as total revenue divided by impressions times 1,000
  • Aggregate with SUM over COUNT, not AVG of per-row ratios
  • Filter on a date range with a half-open interval
  • Use HAVING for the minimum impression threshold
  • Order the output so the answer is readable
Key Topics to Cover
SQL aggregation
eCPM
HAVING
ad monetization
date filtering
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 report eCPM per network as a share of the country average?
  • How would you handle revenue reported in different currencies?
  • How would you compute day-over-day eCPM change per network?
  • Why might eCPM rise while total revenue falls?
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

Assume impressions(impression_id, event_ts, app_id, ad_network, country, revenue_usd) with one row per served impression and revenue already in USD (bidding networks report it per impression; for wa...

Approach

eCPM = 1000⋅∑revenueimpressions1000 \cdot \frac{\sum revenue}{\text{impressions}}. Group by network and country, filter rows to the window in WHERE, and drop small groups in HAVING because a country with 40 impressions can...


Submit Your Answer
Markdown supported

Related Questions