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.

You have ad delivery logs for a shop-ads system.
ad_impressionsimpression_id
STRING (PK)
ts
TIMESTAMP (UTC)
user_id
STRING
shop_id
STRING
country
STRING
region
STRING
ad_slot
STRING
ad_clicksclick_id
STRING (PK)
impression_id
STRING (FK →
ad_impressions.impression_id
)
ts
TIMESTAMP (UTC)
ad_billingimpression_id
STRING (FK →
ad_impressions.impression_id
)
bill_ts
TIMESTAMP (UTC)
billing_model
STRING
'CPC'
,
'CPM'
revenue_usd
NUMERIC
Assume timestamps are UTC and you should use bill_ts as the source of truth for revenue timing.
Write a SQL query to compute ads revenue by geography for the last 30 days:
country
and
region
.
country
,
region
total_revenue_usd
impressions
clicks
ctr
= clicks / impressions
revenue_per_1k_impressions
= 1000 * total_revenue_usd / impressions
total_revenue_usd
descending.