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
Join and Aggregate User Behavior
00:00
5 left

Join and Aggregate User Behavior

MediumSQL · PostgreSQL

Problem

Dentsu International's Merkury audience activation data includes users, campaigns, and behavioral events. Write a PostgreSQL query that summarizes campaign performance during January 2025.

Requirements

  1. Use campaigns as the reporting base so campaigns with no in-window activity remain in the output.
  2. Count distinct engaged users and calculate impressions, clicks, conversions, and total conversion value.
  3. Calculate click-through rate as clicks divided by impressions and conversion rate as conversions divided by clicks. Return NULL when the denominator is zero.
  4. Order results by campaign_id ascending.

Schema

users
ColumnTypeDescription
user_idPKINTUnique audience user identifier
user_nameVARCHAR(100)User display name
segmentVARCHAR(50)Audience segment assigned to the user
campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
campaign_nameVARCHAR(150)Campaign name
channelVARCHAR(50)Marketing activation channel
user_events
ColumnTypeDescription
event_idPKINTUnique behavioral event identifier
user_idINTUser associated with the event
campaign_idINTCampaign that generated the event
event_timeTIMESTAMPTimestamp when the event occurred
event_typeVARCHAR(30)Behavioral event type
event_valueDECIMAL(12,2)Attributed monetary value, generally populated for conversions
Tablesuserscampaignsuser_events
Interviewer

Your question is Join and Aggregate User Behavior. 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.