Is there a way to write a mysql select statement to run a count for a particular 1 field only, if greater than zero and equal to zero.
I could write 2 statements to achieve this but is it possible to do it in a single statement.
Something like this perhaps:
SELECT SUM(CASE WHEN x > 0 THEN 1 ELSE 0 END) as GreatherThanZero
, SUM(CASE WHEN x = 0 THEN 1 ELSE 0 END) as EqualZero
FROM table
WHERE x >= 0
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