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 Night Booking Flag
00:00
5 left

First Night Booking Flag

MediumSQL · PostgreSQL

Problem

Given a bookings table and a listings attribute table (e.g. country), write SQL to compute how many listings were booked for the first time ever on each day.

Asked in the technical phone screen stage. The table setup is visible in the post, and the first booked per day metric was confirmed by the OP in a reply.

Output

  1. One row per booking date where at least one listing was booked for the first time ever
  2. Columns: booking_date, first_time_booked_listings
  3. Count each listing only on the date of its earliest booking, and ignore later bookings for that same listing
  4. Sort by booking_date ascending

Schema

bookings
ColumnTypeDescription
booking_idPKBIGINTUnique booking record identifier
listing_idBIGINTIdentifier of the listing that was booked
booking_dateDATEDate when the booking was created
guest_idBIGINTIdentifier of the guest who made the booking
listings_attributes
ColumnTypeDescription
listing_idPKBIGINTUnique listing identifier
countryVARCHAR(64)Listing country
cityVARCHAR(128)Listing city
Tablesbookingslistings_attributes
Interviewer

Your question is First Night Booking Flag. 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.