I would like to group all the values that are negative and all positive, any ideas how to do this?
GROUP BY SIGN (field) should work.
SELECT SUM(CASE WHEN SomeColumn < 0 THEN 1 ELSE 0 END) AS negative_values, SUM(CASE WHEN SomeColumn >=0 THEN 1 ELSE 0 END) AS non_negative_values FROM YourTable
Stefan . , 0 ,
GROUP BY `field` >= 0
- :
select count(*), IF(foo >= 0, "pos", "neg") as sign from test group by sign;
foo -
EDIT: Stefan , , , .