房间和应用程序之间存在一对一的关系意味着应用程序必须占用一个房间。如果我想获得未被应用程序占用的空间,如何编写sql来查询
答案 0 :(得分:3)
select *
from room r
where not exists (select 1
from application a
where a.roomId = r.roomId)
OR
select *
from room r left outer join
application a on r.roomId = a.roomId
where a.roomId is null
答案 1 :(得分:2)
试试这个
SELECT roomID,description FROM room WHERE roomID NOT IN ( SELECT roomID from application )
答案 2 :(得分:2)
算法:
它们之间的区别在于任何应用程序都没有使用的房间
select roomID from room where roomID not in (select roomID from application)
应该这样做。