PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches

Quick Overview

This question evaluates SQL data manipulation and revenue attribution skills, testing the ability to aggregate and compute business metrics such as total revenue, impressions, clicks, CTR, and revenue per 1k impressions from ad impressions, clicks, and billing records.

  • easy
  • Meta
  • Data Manipulation (SQL/Python)
  • Data Scientist

Compute ads revenue by geography in SQL

Company: Meta

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Technical Screen

You have ad delivery logs for a shop-ads system. ## Tables ### `ad_impressions` - `impression_id` STRING (PK) - `ts` TIMESTAMP (UTC) - `user_id` STRING - `shop_id` STRING - `country` STRING - `region` STRING - `ad_slot` STRING ### `ad_clicks` - `click_id` STRING (PK) - `impression_id` STRING (FK → `ad_impressions.impression_id`) - `ts` TIMESTAMP (UTC) ### `ad_billing` - `impression_id` STRING (FK → `ad_impressions.impression_id`) - `bill_ts` TIMESTAMP (UTC) - `billing_model` STRING - values: `'CPC'`, `'CPM'` - `revenue_usd` NUMERIC - For CPC, revenue is recorded on the clicked impression; for CPM, revenue is recorded per impression. Assume timestamps are UTC and you should use `bill_ts` as the source of truth for revenue timing. ## Task Write a SQL query to compute **ads revenue by geography** for the **last 30 days**: - Group by `country` and `region`. - Output columns: - `country`, `region` - `total_revenue_usd` - `impressions` - `clicks` - `ctr` = clicks / impressions - `revenue_per_1k_impressions` = 1000 * total_revenue_usd / impressions - Return only geographies with at least **100,000 impressions** in the period. - Order by `total_revenue_usd` descending.

Quick Answer: This question evaluates SQL data manipulation and revenue attribution skills, testing the ability to aggregate and compute business metrics such as total revenue, impressions, clicks, CTR, and revenue per 1k impressions from ad impressions, clicks, and billing records.

Last updated: Mar 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Compute ad impression conversion rates - Meta (medium)
  • Count unconnected posts and reactions - Meta (medium)
  • Count heavy callers in 7 days - Meta (medium)
  • Write SQL for call metrics - Meta (medium)
  • Write SQL for multi-account metrics - Meta (medium)