Sum of row Depending on data in sql server -
i have table store customerid, amount , vouchartype transaction table store multiple entry single customer. vouchartype 'd' debit , 'c' credit , amount have positive value. want sum of individual customer debit value should subtract credit value.
please me
here 1 solution. other 'c' considered positive. might need reverse sign depending on need.
select customerid, sum(case when vouchartype = 'c' -amount else amount end) amount yourtable group customerid
Comments
Post a Comment