mysqlgroup-bysumifnull

GROUP result value if null


I can't do this query :

TABLE:

------------
NOTES  | TOTAL
------------
NULL    |  23
NULL    |  12
pay1    | -13
pay2    | -23
-------------

RESULTS :

------------
NOTES   | TOTAL
------------
SELL    |  35
pay1    | -13
pay2    | -23
-------------

I need sum all NULL fields and group with the name " SELL ".


Solution

  • select IFNULL(NOTES,'SELL') n,SUM(TOTAL) FROM records GROUP BY n;