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
First-Touch Booking Attribution
00:00
5 left

First-Touch Booking Attribution

MediumSQL · PostgreSQL

Problem

Given a table of marketing campaigns and a table of user bookings, write a query to attribute bookings to the correct campaign using a first-touch attribution logic for StyleSeat.

Use campaign touches that occurred at or before each booking. Include bookings without an eligible campaign touch, and resolve simultaneous touches using the lowest touch identifier.

Output

  1. One row per booking, ordered by booking_at, then booking_id.
  2. Return booking_id, user_id, booking_at, booking_amount, attributed_campaign_id, attributed_campaign_name, and first_touch_at.
  3. Keep unmatched bookings with null attribution fields.

Schema

marketing_campaigns
ColumnTypeDescription
campaign_touch_idPKINTUnique identifier for a campaign touch
user_idVARCHAR(20)StyleSeat user exposed to the campaign
campaign_idVARCHAR(20)Marketing campaign identifier
campaign_nameVARCHAR(100)Human-readable campaign name
channelVARCHAR(40)Marketing channel that generated the touch
touch_atTIMESTAMPTimestamp when the user received or interacted with the campaign
user_bookings
ColumnTypeDescription
booking_idPKINTUnique booking identifier
user_idVARCHAR(20)StyleSeat user who made the booking
booking_atTIMESTAMPTimestamp when the booking was created
booking_amountNUMERIC(10,2)Booking value in dollars
Tablesmarketing_campaignsuser_bookings
Interviewer

Your question is First-Touch Booking Attribution. 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.