22,302
社区成员




;with ach as
(
select a.orderid,sum(case when b.productid in (1101,1102) then 1 else 0 end) cnt,
count(b.id) tnum
from Orders a join Details b on a.orderid = b.orderid
group by a.orderid
)
select orderid
from ach
where cnt = tnum and cnt = 2
--
A B C 就把in里面的改了,2改为3
SELECT a.* FROM [Orders] a INNER JOIN [Details] b
ON a.orderID=b.OrderID
INNER JOIN [products] c
ON b.productid=c.productid
WHERE c.productName IN ('A','B','C')
select * from 订单主表Order where orderID in(
select orderID from (
select
r = row_number() over(partition by 商品ID order by 商品ID),
orderID, 商品ID
from 明细表Detail
where 商品ID in('A','B','C')
group by orderID, 商品ID
) a where a.r=3
)