sarasa
sarasa

Reputation: 15

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 ".

Upvotes: 1

Views: 8443

Answers (3)

AdrianBR
AdrianBR

Reputation: 2588

SELECT 
IFNULL(NOTES,'SELL')as NOTES,
SUM(TOTAL)  as TOTAL
FROM records 
GROUP BY notes
ORDER BY IFNULL(NOTES,'a')

Upvotes: 0

Jarod
Jarod

Reputation: 1712

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

Upvotes: 3

Sheeban Singaram
Sheeban Singaram

Reputation: 357

Check the name column which as NULL value using IF conditional statement and replace with "SELL" text.

select IF(name is  NULL, "SELL", name) as name, sum(total) as total from content group by name;

Upvotes: 0

Related Questions