22,209
社区成员
发帖
与我相关
我的任务
分享
-- 要求查询订购了所有产品顾客的cid值
select cid
from orders
group by cid
having count(distinct pid)=(select count(1) from products)
select c.cid
from CUSTOMERS c
where not exists ( select *
from products p
where not exists ( select *
from orders o
where p.pid=o.pid )
and o.cid=c.CID );--这个条件拿到外层,感觉逻辑更清晰一些.