gpt4 book ai didi

mysql - 如何在 MySQL 中使用关键字 IN OR 内部连接 ​​3 个表?

转载 作者:行者123 更新时间:2023-11-29 00:39:31 25 4
gpt4 key购买 nike

如何正确使用此 IN OR 选择语句? (除 where bdt.active='yes' 外,一切正常)

SELECT bdt.*, specials.*, stars.* 
FROM bdt INNER JOIN specials ON bdt.id = specials.id
INNER JOIN stars ON specials.id=stars.id
WHERE bdt.active='yes'
AND bdt.business_type IN ('entertainment')
OR bdt.business_subtype IN ('entertainment')
OR bdt.subtype2 IN ('entertainment')
OR specials.type IN ('entertainment')

最佳答案

您只需要在第二个 AND 条件中使用方括号 (),如下所示:

SELECT bdt.*, specials.*, stars.* 
FROM bdt INNER JOIN specials ON bdt.id = specials.id
INNER JOIN stars ON specials.id=stars.id
WHERE bdt.active='yes'
AND (bdt.business_type IN ('entertainment')
OR bdt.business_subtype IN ('entertainment')
OR bdt.subtype2 IN ('entertainment')
OR specials.type IN ('entertainment'))

关于mysql - 如何在 MySQL 中使用关键字 IN OR 内部连接 ​​3 个表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12869942/

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