My Select SUM query returns null. It should return 0

后端 未结 5 800
自闭症患者
自闭症患者 2020-12-09 01:56

I\'m trying to sum up Customer balances using the following query:

select sum(balance) from mytable where customer = \'john\' 

However, if

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 02:24

    Maybe you are thinking of COUNT's behaviours?

    COUNT(Field) will return 0 but SUM(Field) returns NULL if there are no matching rows.

    You need an ISNULL or COALESCE

    COALESCE or ISNULL

提交回复
热议问题