列出已为每位客户收到货件的城市

时间:2015-05-25 05:24:21

标签: sql oracle mysqli

CUSTOMER (cust_id, cust_name, annual_revenue)
SHIPMENT (shipment_id, cust_id, weight, truck_no, dest)
TRUCK (truck_no, driver_name)
CITY (city_name, population)

select s.dest from shipment s
where not exists (
  (select cust_id from customer)
    except
  (select ss.cust_id from customer ss where ss.dest = s.dest)
);

给出错误:

  

ORA-00907:缺少右括号

为什么???

1 个答案:

答案 0 :(得分:1)

您可以将其重写为:

select dest
from shipment
group by dest
having count(distinct cust_id) = (select count(*) from customer)

它更容易理解并且性能更好,因为它不使用任何相关的子查询。