Campaign Click-Through Rate
Each row of campaigns has total impressions and clicks.
Compute the click-through rate as a percentage: 100.0 * clicks / impressions, rounded with ROUND(x, 2). If a campaign has 0 impressions its ctr_pct must be NULL (not an error and not 0).
Return columns campaign_id, name, ctr_pct. Order by campaign_id ascending.
Schema
CREATE TABLE campaigns ( campaign_id INTEGER PRIMARY KEY, name TEXT NOT NULL, impressions INTEGER NOT NULL, clicks INTEGER NOT NULL );
Sample data
campaigns
| campaign_id | name | impressions | clicks |
|---|---|---|---|
| 1 | Spring Sale Search | 12000 | 360 |
| 2 | Brand Video | 50000 | 410 |
| 3 | Retargeting Display | 8000 | 296 |
| 4 | Newsletter Promo | 0 | 0 |
| 5 | Ramadan Offers | 2500 | 125 |
Hint 1
Multiply by 100.0 (not 100) so SQLite does real division instead of integer division.
Hint 2
NULLIF(impressions, 0) returns NULL for zero, and dividing by NULL gives NULL.
Good practice for: Digital Marketing Specialist, Data Analyst, Business Analyst
SQL (SQLite)
Run checks your query on the sample data (Ctrl + '). Submit also checks hidden databases.