I have this data in a table:
id account status 1 8 1 2 8 4 4 8 3 5 8 1 6 1 4 7 1 3
I want a single query to return me the account number, and if any of the status' for that account is <3 then return 'Yes' else 'No'. So, these results:
account pending 8 'Yes' 1 'No'
I had:
SELECT account, IF(status>2,'No','Yes') as pending FROM table GROUP BY account;
But it only seems to take into account the first row for each account. (ex. id 1's status=1 so even if id 4's status is changed so status=1, it'll still think all is greater than 2.)
I really appreciate any help. I normally can do decent query design, but this is giving me a brain cramp. :)
SELECT account, IF(max(status)>2,'No','Yes') as pending
FROM table
GROUP BY account
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With