Consecutive Available Seats

2pts
Cinema

Problem Statement

Cinema booking systems need to show users seats that are next to each other. A seat is considered available if the free column is 1.

Write an SQL query to report all the consecutive available seats in the movie theater.

Rules:

  • Two seats are consecutive if their seat_id values differ by exactly 1.
  • Only return seat_id values for seats that have at least one neighboring seat also marked as free.
  • The result should contain the seat_id column.
  • Results must be sorted by seat_id in ascending order.
Tests your understanding of
Basic SQL, Self Join, Filtering and Distinct

Input Tables

cinema
seat_id(INTEGER)free(INTEGER)
11
20
31
41
51

Expected Output

seat_id(INTEGER)
3
4
5

Tags

EasyBasic SQLSelf JoinFilteringDistinct
10-15 min
65%

Hints