开发者

mysql negtaive value

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜