Sai Reddy

Sai Reddy

  • NA
  • 214
  • 28.4k

Find an available Seats which are adjacent to each other?

Jul 3 2018 7:48 AM
I found the following question in one blog. i am unable to find the logic. Please help me here.
 
The question is: Find an available Seats(Status – ‘y’) which are adjacent to each other.
 
CREATE TABLE tbl_MoviePlex (Seatid INT, Status CHAR(1))
INSERT INTO tbl_MoviePlex VALUES
(1,'y')
,(2,'n')
,(3,'y')
,(4,'y')
,(5,'n')
,(6,'y')
SELECT
a.Seatid
,b.Seatid
FROM tbl_MoviePlex a
INNER JOIN tbl_MoviePlex b
on a.Seatid = b.Seatid + 1
and a.Status = b.Status
 
What is happenning at on a.Seatid = b.Seatid + 1 ?

Answers (1)