1

我不能做这个查询:

桌子:

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

结果 :

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

我需要对所有 NULL 字段和名称为“ SELL ”的组求和。

4

3 回答 3

2
select IFNULL(NOTES,'SELL') n,SUM(TOTAL) FROM records GROUP BY n;
于 2013-10-19T07:57:19.600 回答
0

使用 IF 条件语句检查作为 NULL 值的名称列并替换为“SELL”文本。

select IF(name is  NULL, "SELL", name) as name, sum(total) as total from content group by name;
于 2013-10-19T07:54:31.723 回答
0
SELECT 
IFNULL(NOTES,'SELL')as NOTES,
SUM(TOTAL)  as TOTAL
FROM records 
GROUP BY notes
ORDER BY IFNULL(NOTES,'a')
于 2013-10-19T08:00:08.707 回答