Digvijay Patil Digvijay Patil - 11 months ago 40
SQL Question

Select rows having same column value more than 3 times

I have a table called

Theater(Sn, SeatVacant)

1 Y
2 Y
3 N
. .
. .
100 Y

I want to book 3 seats(should be continuous). How can i get the continuous vacant seat.

select f1.sn, f2.sn, f3.sn from Theater f1
inner join Theater f2 on f1.sn=f2.sn + 1 
inner join Theater f3 on f1.sn=f3.sn + 2
where f1.SEATVACANT='Y' and f2.SEATVACANT='Y' and f3.SEATVACANT='Y'