甲骨文 sql 查询 select
oracle sql query select
table游客
table留下来
table酒店
我想打印去过希尔顿但没去过大陆的游客的名字所以去过希尔顿和大陆的游客都不应该被打印
您可以使用 exists
和 not exists
:
select t.*
from tourists t
where
exists (
select 1
from stay s
inner join hotels h on h.hcode = s.hcode
where s.tcode = t.tcode and h.name = 'Hilton'
) and not exists (
select 1
from stay s
inner join hotels h on h.hcode = s.hcode
where s.tcode = t.tcode and h.name = 'Continental'
)
table游客
table留下来
table酒店
我想打印去过希尔顿但没去过大陆的游客的名字所以去过希尔顿和大陆的游客都不应该被打印
您可以使用 exists
和 not exists
:
select t.*
from tourists t
where
exists (
select 1
from stay s
inner join hotels h on h.hcode = s.hcode
where s.tcode = t.tcode and h.name = 'Hilton'
) and not exists (
select 1
from stay s
inner join hotels h on h.hcode = s.hcode
where s.tcode = t.tcode and h.name = 'Continental'
)