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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
SQL for Consecutive Theater Seats
00:00
5 left

SQL for Consecutive Theater Seats

MediumSQL · PostgreSQL

Problem

The Zulily app needs to recommend the best available seating block for a live shopping theater event. Write a PostgreSQL query that finds one block of consecutive available seats for a specified screening.

Requirements

  1. Consider only screening 101 and seats whose status is available.
  2. Treat seats as consecutive only within the same row and seat rank, where rank 1 is the best rank.
  3. Select the block with the best rank first, then the greatest number of consecutive seats, then the earliest row and starting seat as deterministic tie-breakers.
  4. Return the screening name, row, rank, starting seat, ending seat, and block length.

Schema

screenings
ColumnTypeDescription
screening_idPKINTUnique screening identifier
screening_nameVARCHAR(100)Name of the Zulily event or show
seat_inventory
ColumnTypeDescription
seat_idPKINTUnique seat inventory identifier
screening_idINTReferences screenings.screening_id
row_labelVARCHAR(10)Theater row label
seat_numberINTNumeric position within the row
seat_rankINTSeat quality rank, with 1 as the best rank
statusVARCHAR(20)Seat availability status
Tablesscreeningsseat_inventory
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.