You work on a video ads platform. You are given three tables and asked to compare CTR during peak hours vs non-peak hours.
Assume the following schemas:
ads
ad_id
STRING (PK)
advertiser_id
STRING
ad_type
STRING -- e.g.,
direct
,
brand
created_at
TIMESTAMP
impressions
impression_id
STRING (PK)
ad_id
STRING (FK →
ads.ad_id
)
user_id
STRING
impression_ts
TIMESTAMP
clicked
BOOLEAN -- whether the impression resulted in a click
conversions (not necessarily needed for CTR, but available)
conversion_id
STRING (PK)
ad_id
STRING (FK →
ads.ad_id
)
user_id
STRING
conversion_ts
TIMESTAMP
impressions.clicked
to count clicks.
Write a SQL query that outputs CTR for:
Required output columns:
hour_type
ENUM(
peak
,
non_peak
)
impressions
clicks
ctr
(Optionally include the CTR difference peak_ctr - non_peak_ctr.)