Banner With the Best Click-Through
Problem
Table: `BannerLog`
```text
+-----------+---------+
| Column | Type |
+-----------+---------+
| event_ref | int |
| event_type| varchar |
| banner_id | int |
+-----------+---------+
Each row is an event for a banner. `event_type` is either 'impression' (the banner was shown) or 'click' (a user clicked it).
```
Report the `banner_id` with the highest **click-through rate**, where click-through rate = (number of 'click' rows) / (number of 'impression' rows) for that banner. If several banners tie on the highest rate, report the one with the smallest `banner_id`. Label the output column `top_banner`.
Tables
Example rows — the live problem includes the full dataset.
| event_ref | event_type | banner_id |
|---|---|---|
| 1 | impression | 101 |
| 2 | click | 101 |
| 3 | impression | 101 |
Expected output
Your answer should return 1 row with the columns top_banner.
Starter code (SQL)
SELECT *
FROM BannerLog;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock