#80

Guests with First Booking to NYC

EASYAggregation & WindowsPOSTGRESQL

Problem Description

A travel accommodation platform wants to identify guests whose very first booking was to New York City. This cohort is a high-value segment — guests who chose NYC as their inaugural destination tend to show stronger long-term engagement and are a primary target for personalized re-marketing campaigns. The `user_booking` table records every reservation a guest has ever made, each with a `destination` city and a `ts_booking` timestamp. A guest's first booking is the one with the earliest `ts_booking`. When two bookings share the exact same timestamp, `reservation_id` ascending is used as the tie-breaker to deterministically identify the true first. Count the number of guests whose first-ever booking destination was `'NYC'` (case-sensitive). Return a single integer labeled `count`.

Topics

window functions

Asked at Companies

airbnb

Solve This Problem

Sign up to access the interactive code editor, run test cases, view the editorial, and get AI-powered feedback on your solution.

Start Solving →