This question evaluates proficiency in data manipulation and analytics, testing skills such as joining event and impression tables, aggregating time-series revenue, and counting distinct active ads broken down by creation source.

You work on an ads platform and need to report active ad revenue broken down by the ad’s creation source.
adsad_id
BIGINT
PK
advertiser_id
BIGINT
creation_source
VARCHAR
'SELF_SERVE'
,
'MANAGED'
,
'API'
created_at
TIMESTAMP
ad_impressionsimpression_id
BIGINT
PK
ad_id
BIGINT
FK → ads.ad_id
impression_time
TIMESTAMP
ad_revenue_eventsevent_id
BIGINT
PK
ad_id
BIGINT
FK → ads.ad_id
event_time
TIMESTAMP
revenue_usd
DECIMAL(18,6)
revenue_usd
from
ad_revenue_events
that occurred that day
for ads that are active that same day
.
Write a SQL query to compute, for each calendar day in a given date range (e.g., :start_date to :end_date, inclusive):
report_date
creation_source
active_ads
(count of distinct active
ad_id
)
active_ad_revenue_usd
(sum of revenue for active ads)
Order results by report_date, then creation_source.