我在表中有这些数据:
id account status 1 8 1 2 8 4 4 8 3 5 8 1 6 1 4 7 1 3
我想要一个查询来返回帐号,如果该帐号的任何状态为<3,则返回'是'否则'否'.所以,这些结果:
account pending 8 'Yes' 1 'No'
我有:
SELECT account, IF(status>2,'No','Yes') as pending FROM table GROUP BY account;
但它似乎只考虑了每个帐户的第一行.(例如,id 1的状态= 1,所以即使id 4的状态改变,因此状态= 1,它仍然认为所有都大于2.)
我非常感谢任何帮助.我通常可以做正确的查询设计,但这给了我一个大脑抽筋.:)
Ran*_*ndy 14
SELECT account, IF(max(status)>2,'No','Yes') as pending
FROM table
GROUP BY account
Run Code Online (Sandbox Code Playgroud)