Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
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
Sign up free to run your codeLog inLn 1
Run your query to see results here.