Seat Requests

Start Timer

0:00:00

Upvote
0
Downvote
Save question
View comments

Let’s say we run seat bookings for an airline. The seats table holds each seat’s current state and the requests table holds new requests. Write a query that processes the requests in order of request_id and returns the final state of every seat.

  • In seats, status is 0 for free, 1 for reserved and 2 for purchased, and person_id is NULL when a seat is free.
  • In requests, request is 1 for reserve and 2 for purchase.

Rules - A person can reserve a seat only if it is free. - A person can purchase a seat if it is free or if they hold the reservation on it. - Any other request is ignored. Also ignore requests for seats that are not in seats. - Return one row per seat in seats, ordered by seat_no.

Example:

Input:

seats table

Column Type
seat_no INTEGER
status INTEGER
person_id INTEGER

requests table

Column Type
request_id INTEGER
request INTEGER
seat_no INTEGER
person_id INTEGER

Output:

Column Type
seat_no INTEGER
status INTEGER
person_id INTEGER
.
.
.
.
.


Comments

Loading comments