gpt4 book ai didi

MySql Where AND OR条件,返回所有数据?

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

我有一个小查询,一次使用“And”,两次使用“Or”,只要我添加第二个 Or,它就会返回所有数据,而不是过滤后的数据。基本上,下面应该返回 John Smith 的所有状态为“有效”或“联系中”的案例

Select
c.Adviser,
l.Status
From
tbl_lead l Inner Join
tbl_clients c On c.client_id = l.client_id
Where
(c.Adviser = 'John Smith' And l.Status = 'active') Or
(l.Status = 'in contact')

谁能看出我哪里出错了?

最佳答案

使用 "IN" 子句。

Select
c.Adviser,
l.Status
From
tbl_lead l Inner Join
tbl_clients c On c.client_id = l.client_id
Where
c.Adviser = 'John Smith' And l.Status IN ('active','in contact')

关于MySql Where AND OR条件,返回所有数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31117951/

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