我在使用paymentmethod 1执行sql查询时遇到问题,显示paymentmethod 3也是。请检查我错在哪里。提前谢谢
mysql - SQL查询没有正确的付款方式-LMLPHP
这是我的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

最佳答案

你需要括号。您的情况评估为:

HAVING (ref <  2) or (user.usersecond = 0 and paymentmethod = 1)

大概你想要:
HAVING (ref <  2 or user.usersecond = 0) and paymentmethod = 1

如果在条件下混合andor,请始终使用括号。

07-27 21:40