我有当前的sql语句:

SELECT count(distinct s.SupplierID)
from Products p join Categories c on p.CategoryID = c.CategoryID
join Suppliers s on s.SupplierID = p.SupplierID and c.CategoryName
IN ('Beverages', 'Seafood');


我很难让它只显示饮料和海鲜,而不仅仅是一种或两种。

最佳答案

您是否尝试过将条件放在WHERE子句中,而不作为连接条件的一部分?例如:

SELECT count(distinct s.SupplierID)
from Products p
join Categories c on p.CategoryID = c.CategoryID
join Suppliers s on s.SupplierID = p.SupplierID
WHERE c.CategoryName IN ('Beverages', 'Seafood');

10-08 13:06