开发者

mysql negtaive value

开发者 https://www.devze.com 2023-02-28 01:06 出处:网络
Please have a look at part of my sql query... COALESCE((sum(i.amount) - COALESCE(sum(i.discount),0)) - COALESCE(SUM(r.rfee+r.tfee+r.ofee),0),0) AS balance_due

Please have a look at part of my sql query...

COALESCE((sum(i.amount) - COALESCE(sum(i.discount),0)) - COALESCE(SUM(r.rfee+r.tfee+r.ofee),0),0) AS balance_due 

As you can see I am using COALESCE to replace NULL with 0, but its not r开发者_JS百科eturning negative value incase of COALESCE(SUM(r.reg_fee+r.tut_fee+r.other_fee),0) is greater than (sum(i.amount) - COALESCE(sum(i.discount),0) , how can i get negative value instead of getting 0. thanks


Try this:

COALESCE(sum(i.amount), 0) - COALESCE(sum(i.discount), 0) - COALESCE(SUM(r.rfee+r.tfee+r.ofee), 0) AS balance_due 
0

精彩评论

暂无评论...
验证码 换一张
取 消