學習網址: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進行左連接