求救!查询至少和....相同的....

来源:百度知道 编辑:UC知道 时间:2024/07/08 02:07:47
查询至少和1002号订单订购的商品种类相同的订单号 订单号(OrderNo) 商品种类(Category) 种类在表Products里 订单号在Orders和Order_Details里具体的结构请看这里

我自己做了下实在做不出来...下面是自己做的错的....select ordernofrom [order details] o1where o1.orderno not in(select ordernofrom productsjoin [order details]on [order details].productno = products.productnowhere category not in (select categoryfrom productsjoin [order details]on [order details].productno = products.productnowhere [order details].orderno = '1002'))请各位高手指点下给个思路... 先谢谢了...

select distinct o.OrderNo
from Orders o,OrderDetails od
where o.OrderNo=od.OrderNo and ProductNo in (
select ProductNo
from products p
where ProductNo in (select ProductNo
from OrderDetails od
where OrderNo='1002' ))
and o.orderNo<>'1002'

/*
select distinct o.OrderNo
from Orders o,OrderDetails od
where o.OrderNo=od.OrderNo and ProductNo in (
select ProductNo
from products p
where ProductNo in (select ProductNo
from OrderDetails od
where OrderNo='1002' ))
and o.orderNo<>'1002'
*/
--上面这个不对,只要其他订单中有1002订单中商品的一种,就会被查出来;不满足要求

select a.orderno from
(select x.orderno orderno,z.category category
from order_details x,
(select a.orderno,b.category from order_details a,products b
w