Clickthrough for active ads

Question

You’re given the following tables, showing information for individual advertising campaigns as well as associated clicks, impressions.

Table: ads

ad_id status
1234 Active
1235 Active
1236 Inactive
4454 Active
4432 Inactive
4430 Active
1299 Active

Table: ad_events

event_id ad_id event_type count
115 1234 Click 500
116 1235 Impression 5000
117 1236 Click 200
118 4454 Impression 6500
119 4432 Click 50
120 4430 Impression 10000
121 1299 Click 150
122 1234 Impression 12000
123 1235 Click 75
124 1236 Impression 2000
125 4454 Click 65
126 4432 Impression 5500
127 4430 Click 100
128 1299 Impression 15000

Given the tables above, write a SQL query to return the clickthrough rate (number of clicks / number of impressions) for all active ads.

You can view/query the data in an interactive SQL fiddle here.

Solution

Access restricted

Subscribe to premium account to see the solution.

Get premium now