I have a table movie
that has id
, movie name
, and status
columns.
id | name | status |
---|---|---|
1 | movie1 | 0 |
2 | movie1 | 1 |
3 | movie1 | 0 |
4 | movie1 | 1 |
5 | movie1 | 0 |
6 | movie1 | 0 |
7 | movie1 | 1 |
8 | movie1 | 0 |
9 | movie1 | 1 |
10 | movie1 | 1 |
11 | movie1 | 0 |
12 | movie1 | 0 |
13 | movie1 | 0 |
Suppose these IDs are seat numbers, and status = 0
means a vacant seat, while status = 1
means an occupied seat.
How can I select 3 consecutive vacant seats?
For example, IDs 11, 12, and 13 are consecutive vacant seats:
id | name | status |
---|---|---|
11 | movie1 | 0 |
12 | movie1 | 0 |
13 | movie1 | 0 |
2
Answers
Find the first
id
of the 3 consecutive movies then use the resultm1.id
as another table and fetch records whose id is betweenm1.id
andm1.id+2
As @Shadow commented:
Here is one way to implement in your scenario
However, considering the context of identifying available seats for a movie, this approach seems a bit off to me. There might be a more efficient way to manage movie seat availability.
Hope this will help!