Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Daily CTR by Campaign Category
00:00
5 left

Daily CTR by Campaign Category

MediumSQL · PostgreSQL

Problem

Given a database schema for ad impressions and clicks, write a query to calculate the daily click-through rate (CTR) grouped by campaign category.

Use the provided tables and include dates and categories with impressions even when no clicks occurred. CTR should be expressed as a percentage.

Output

  1. One row per impression date and campaign category.
  2. Columns: campaign_category, impression_date, impressions, clicks, and ctr_percentage.
  3. Include zero-click groups, exclude clicks that do not match an impression, and order by impression_date, then campaign_category.

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
categoryVARCHAR(50)Campaign category
ad_impressions
ColumnTypeDescription
impression_idPKINTUnique impression identifier
campaign_idINTCampaign associated with the impression
impression_dateTIMESTAMPTimestamp when the impression occurred
ad_clicks
ColumnTypeDescription
click_idPKINTUnique click identifier
impression_idINTImpression associated with the click
clicked_atTIMESTAMPTimestamp when the click occurred
Tablescampaignsad_impressionsad_clicks
Interviewer

Your question is Daily CTR by Campaign Category. Start with the requirements and the three tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.