现在一个数据表A, 有字段rwhao(nvarchar), net(decimal) ,现在要按 rwhao来分组统计net ,如果net 统计结果为NULL,则显示为0 ,如何统计
我这统计不显示
SELECT RWHao, COALESCE (SUM(NET), 0) AS tj
FROM dbo.tbDBDataHj AS B
GROUP BY RWHao
------解决方案--------------------
isnull(NET,0)
------解决方案--------------------
SELECT RWHao, isnull(SUM(NET), 0) AS tj
FROM dbo.tbDBDataHj AS B
GROUP BY RWHao
------解决方案--------------------
楼主你这样有点小题大做了,
SELECT RWHao ,
ISNULL(SUM(NET), 0) AS tj
FROM dbo.tbDBDataHj AS B
GROUP BY RWHao
COALESCE 函数的确很有用,比isnull有用的多:
一个非常有用的函数——COALESCE
------解决方案--------------------
SELECT RWHao, COALESCE (SUM(ISNULL(NET,0)), 0) AS tj
FROM dbo.tbDBDataHj AS B
GROUP BY RWHao