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
精彩评论