您好我希望有人可以帮助查询adventureworks2012 db,
我试图找到客户购买完全相同的两件商品的所有订单。
EG
select p.*
from FactInternetSales f
inner join DimProduct p on p.ProductKey = f.ProductKey
where ProductAlternateKey in ('BK-M18B-40','TI-M267')
示例SalesOrderNumber包含:SO58845
任何帮助,将不胜感激。
谢谢。
尝试在一个productAlternateKey的子选择上进行内连接,然后只需在原始的Where clasue中查找另一个productAlternateKey。
示例脚本(未测试):
select p.*
from FactInternetSales f
inner join DimProduct p on p.ProductKey = f.ProductKey
inner join (select p2.*
from FactInternetSales f2
inner join DimProduct p2 on p2.ProductKey = f2.ProductKey
where ProductAlternateKey = 'TI-M267') innerSelect on p.ProdctKey = innerselect.ProductKey
where ProductAlternateKey ='BK-M18B-40'