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
Query Guest Retention by Channel
00:00
5 left

Query Guest Retention by Channel

HardSQL · PostgreSQL

Problem

Marriott International wants to monitor whether guests who completed a booking return in the following month. Write a PostgreSQL query that calculates monthly guest retention by the guest's booking channel in the cohort month.

Requirements

  1. Consider only bookings with booking_status = 'Completed'.
  2. Treat each guest as one monthly booking-channel cohort member, even if the guest has multiple bookings in that month.
  3. For each cohort month and booking channel, calculate the number of prior-month guests, the number who completed another booking in the next month, and the retention rate as a percentage.
  4. Replace a missing booking channel with Unknown, and sort by retention month and booking channel.

A retained guest may return through any booking channel. The segment represents the channel used in the cohort month.

Schema

guests
ColumnTypeDescription
guest_idPKINTUnique guest identifier
guest_nameVARCHAR(100)Guest full name
loyalty_tierVARCHAR(30)Marriott Bonvoy loyalty tier
bookings
ColumnTypeDescription
booking_idPKINTUnique booking identifier
guest_idINTGuest who made the booking
booked_atTIMESTAMPTimestamp when the booking was made
booking_channelVARCHAR(40)Booking source
booking_statusVARCHAR(20)Booking lifecycle status
Tablesguestsbookings
Interviewer

Your question is Query Guest Retention by Channel. 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.