Customer Table
----------------------
CustomerName
Peter
Sam
Sales Table
-----------------------
ProductName Customer
Cloth Peter
Mobile Peter
Cloth Sam
Laptop Sam
预期结果
Customer
Sam
我想要结果作为购买“衣服”而不是“手机”的客户,我试过了
select c.CustomerName from Customer c inner join Sales s1 on (s1.customer = c.customername and s1.productname = 'Cloth') inner join Sales s2 on (s2.customer = c.customername and s2.productname != 'Mobile');
但它总是返回两个条目
Customer
Peter
Sam
Sam