13. Campaign Click-Through Rate

Easy

ad_events(event_id, campaign_id, event_type, event_at)

For September 2026, return each campaign's click-through rate as clicks / impressions * 100, named ctr_pct, ordered by campaign_id.

A campaign with impressions but no clicks has a CTR of 0, not NULL, so this cannot be a plain average over clicks. Campaigns with no impressions at all do not appear, since dividing by zero has no meaning here.

Tables

ad_events

event_id  campaign_id  event_type  event_at
--------  -----------  ----------  -------------------
1         1            impression  2026-09-01 10:00:00
2         1            impression  2026-09-02 10:00:00
3         1            click       2026-09-02 11:00:00
4         2            impression  2026-09-05 10:00:00
5         2            click       2026-09-05 11:00:00
6         3            impression  2026-09-07 10:00:00
7         3            impression  2026-09-08 10:00:00
8         4            click       2026-09-09 10:00:00
... 1 more row(s)

Expected result

campaign_id  ctr_pct
-----------  ---------
1            50.00000
2            100.00000
3            0.00000

Sign in to write and run your own code.

Write one SELECT query