Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Query Guest Retention by Channel

HardSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Query Guest Retention by Channel. Start with the requirements and the two tables on the right.

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.

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results