create table movie(
seat varchar(50),occupancy int
);
insert into movie values('a1',1),('a2',1),('a3',0),('a4',0),('a5',0),('a6',0),('a7',1),('a8',1),('a9',0),('a10',0),
('b1',0),('b2',0),('b3',0),('b4',1),('b5',1),('b6',1),('b7',1),('b8',0),('b9',0),('b10',0),
('c1',0),('c2',1),('c3',0),('c4',1),('c5',1),('c6',0),('c7',1),('c8',0),('c9',0),('c10',1);
with cte as(
select *, substring(seat,1,1) as row , cast(substring(seat,2,2) as int) as seat_id
,sum(occupancy) over(partition by substring(seat,1,1) rows between current row and 3 following) as four_sum
,count(occupancy) over(partition by substring(seat,1,1) rows between current row and 3 following) as four_cnt
from movie
)
,cte1 as (
select * from cte c1
where four_sum = 0 and four_cnt =4
)
select a.seat
from cte a
join cte1 b on a.row =b.row and a.seat_id between b.seat_id and b.seat_id+3
To embed this project on your website, copy the following code and paste it into your website's HTML: