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 Region and Device
00:00
5 left

CTR by Region and Device

MediumSQL · PostgreSQL

Problem

Yelp Ads needs a performance report for advertiser 101. Write a PostgreSQL query that calculates click-through rates for impressions served during June 2024, segmented by geographic region and device type.

Requirements

  1. LEFT JOIN the impression and click logs so impressions without clicks remain in the report.
  2. Return one row per region and device type, including NULL dimensions as Unknown.
  3. Calculate total impressions, distinct clicked impressions, and CTR as a percentage rounded to two decimals. Avoid counting multiple click events for one impression more than once.
  4. Sort by region and device type, with NULL source dimensions last.

Schema

ad_impressions
ColumnTypeDescription
impression_idPKINTUnique impression identifier
advertiser_idINTYelp Ads advertiser identifier
regionVARCHAR(50)Geographic region where the impression occurred
device_typeVARCHAR(20)Device used to view the advertisement
impression_tsTIMESTAMPTimestamp when the ad impression occurred
ad_clicks
ColumnTypeDescription
click_idPKINTUnique click event identifier
impression_idINTImpression associated with the click
clicked_atTIMESTAMPTimestamp when the click occurred
Tablesad_impressionsad_clicks
Interviewer

Your question is CTR by Region 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.