, aginst = + 1:
SELECT ...
FROM Seats A
JOIN Seats B ON A.Row = B.Row AND A.Column = B.Column+1
WHERE A.IsReserved = 0
AND B.IsReserved = 0
3-4 = + 1, +2, +3. , CTE, . .
:
create table Seats (Row int not null
, Col int not null
, IsReserved bit not null
, constraint pkSeatsRowColumn primary key (Row, Col));
go
insert into Seats (Row, Col, IsReserved)
select 1,1,0 union all
select 1,2,0 union all
select 1,3,1 union all
select 1,4,0 union all
select 1,5,0 union all
select 1,6,0 union all
select 2,1,0;
with cteAnchor as (
SELECT Row, Col, 1 as [length]
FROM Seats
WHERE IsReserved = 0)
, cteRecursive as (
SELECT Row, Col, [length]
FROM cteAnchor
UNION ALL
SELECT c.Row, c.Col, c.[length]+1
FROM Seats s
JOIN cteRecursive c
ON s.Row = c.Row and s.Col = c.Col+c.[length]
WHERE s.IsReserved = 0)
select * from cteRecursive
, . 3, WHERE, (1,4), , 2 .