当我使用paymentmethod 1执行我的sql查询时,我遇到了问题.显示它还显示了paymentmethod 3.请检查我错在哪里.提前致谢
这是我的SQL查询: -
SELECT (SELECT COUNT(u.`upperuserid`)
FROM user u
WHERE u.upperuserid = user.usernewid
) as ref,
usernewid,
user.paymentmethod,usersecond, mod_date
from user
HAVING ref < 2 or user.usersecond=0 and paymentmethod = 1
Run Code Online (Sandbox Code Playgroud)
ref < 2 or user.usersecond=0 and paymentmethod = 1
Run Code Online (Sandbox Code Playgroud)
运算符优先级.这被解释为:
(ref < 2) or (user.usersecond=0 and paymentmethod = 1)
Run Code Online (Sandbox Code Playgroud)
由于有问题的记录匹配ref < 2,它们将被退回.
通过在括号中对表达式进行分组,明确定义逻辑的优先级:
(ref < 2 or user.usersecond=0) and (paymentmethod = 1)
Run Code Online (Sandbox Code Playgroud)
你需要括号.您的病情评估为:
HAVING (ref < 2) or (user.usersecond = 0 and paymentmethod = 1)
Run Code Online (Sandbox Code Playgroud)
大概你想要:
HAVING (ref < 2 or user.usersecond = 0) and paymentmethod = 1
Run Code Online (Sandbox Code Playgroud)
如果您在混合and和or条件下,请始终使用括号.
| 归档时间: |
|
| 查看次数: |
57 次 |
| 最近记录: |