gpt4 book ai didi

mysql - 使用 'in' 查找两个值的 join 函数

转载 作者:行者123 更新时间:2023-11-29 19:06:16 27 4
gpt4 key购买 nike

我有当前的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');

关于mysql - 使用 'in' 查找两个值的 join 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43479466/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com