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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
CTR by Campaign and Device
00:00
5 left

CTR by Campaign and Device

MediumSQL · PostgreSQL

Problem

LG Ad Solutions needs to compare campaign click-through rates across device types. Write a SQL query that calculates aggregated impressions, clicks, and CTR for each campaign and device combination during the 30-day period ending on September 15, 2026.

Output

  1. One row per campaign and device type, with columns campaign_name, device_type, impressions, clicks, and ctr_percent.
  2. Include only performance records from August 16, 2026 through September 15, 2026, inclusive. Treat NULL clicks as zero, and return no CTR for groups whose total impressions are zero.
  3. Sort by campaign name alphabetically, then device type alphabetically, with NULL device types last.

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
campaign_nameVARCHAR(150)Campaign display name
advertiser_nameVARCHAR(150)Advertiser associated with the campaign
campaign_daily_performance
ColumnTypeDescription
performance_idPKINTUnique daily performance record
campaign_idINTCampaign associated with the performance record
performance_dateDATEDate represented by the metrics
device_typeVARCHAR(40)Device category receiving the ad impression
impressionsINTNumber of ad impressions
clicksINTNumber of ad clicks
Tablescampaignscampaign_daily_performance
Interviewer

Your question is CTR by Campaign and Device. Start with the requirements and the two 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.