My Select SUM query returns null. It should return 0

后端 未结 5 813
自闭症患者
自闭症患者 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条回答
  •  猫巷女王i
    2020-12-09 02:14

    Try this:

    select COALESCE(sum(balance),0) from mytable where customer = 'john' 
    

    This should do the work. The coalesce method should return the 0.

提交回复
热议问题