Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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
Randomly Group Passenger IDs
00:00
5 left

Randomly Group Passenger IDs

MediumSQL · PostgreSQL

Problem

American Airlines wants to run a randomized experiment using eligible AAdvantage passengers from recent flight bookings. Write a PostgreSQL query that assigns each eligible passenger ID to one of three mutually exclusive groups: 10% treatment, 10% holdout, and 80% control.

Requirements

  1. Include only passengers with a confirmed booking between 2026-07-01 and 2026-07-31.
  2. Remove duplicate passengers who have multiple qualifying bookings.
  3. Randomize the eligible passengers, then assign the first 10% to treatment_10_pct, the next 10% to holdout_10_pct, and the remainder to control_80_pct.
  4. Return each passenger ID, assigned group, and position within that group. For sample data with 10 eligible passengers, the groups should contain 1, 1, and 8 passengers.

Schema

passengers
ColumnTypeDescription
passenger_idPKINTEGERUnique passenger identifier
passenger_nameVARCHAR(100)Passenger name
flight_bookings
ColumnTypeDescription
booking_idPKINTEGERUnique booking identifier
passenger_idINTEGERPassenger associated with the booking
flight_numberVARCHAR(10)American Airlines flight number
flight_dateDATEScheduled flight date
booking_statusVARCHAR(20)Booking status
Tablespassengersflight_bookings
Interviewer

Your question is Randomly Group Passenger IDs. 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.