MySQL表连接查询

学习网址:MySQL表连接查询,写这篇文章只是为了保存这个网址

答案:

select DISTINCT c1.seat_id
FROM cinema c1
LEFT JOIN
cinema c2
ON
ABS(c1.seat_id-c2.seat_id)=1
where c1.free=1 and c2.free=1
ORDER BY c1.seat_id

 

 

 顺便说一下,ABS(X)函数的用法:返回X的绝对值。这里的用法是:按照左表与右边的seat_id差值为1进行左连接