Skip to content
RED SAGSkills

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_idnameimpressionsclicks
1Spring Sale Search12000360
2Brand Video50000410
3Retargeting Display8000296
4Newsletter Promo00
5Ramadan Offers2500125
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.