Returning the sum of a select statement SQL -
i have created select statement:
select arii2.amount ar_customer arc2 inner join ar_customer_site arcs2 on arc2.customer_id = arcs2.customer_id , arcs2.customer_id = arc2.customer_id inner join ar_customer_system arcsys2 on arcs2.customer_site_id = arcsys2.customer_site_id inner join ar_branch arb2 on arb2.branch_id = arc2.branch_id inner join ar_invoice arin2 on arin2.customer_site_id = arcs2.customer_site_id inner join ar_invoice_item arii2 on arii2.invoice_id = arin2.invoice_id inner join sy_system sysy2 on arcsys2.system_id = sysy2.system_id arin2.invoice_date > dateadd(year, -1, getdate()) , arc2.customer_number = '300000' , arii2.[description] ('warranty credit') or arii2.[description] = ('warranty credit t') group arii2.amount
that returns following results.
2031.00 1458.98 1272.50 620.00 160.00
my thought put sum around amount , return desired value of 5542.48 (the total of values).
select sum(arii2.amount) ar_customer arc2 inner join ar_customer_site arcs2 on arc2.customer_id = arcs2.customer_id , arcs2.customer_id = arc2.customer_id inner join ar_customer_system arcsys2 on arcs2.customer_site_id = arcsys2.customer_site_id inner join ar_branch arb2 on arb2.branch_id = arc2.branch_id inner join ar_invoice arin2 on arin2.customer_site_id = arcs2.customer_site_id inner join ar_invoice_item arii2 on arii2.invoice_id = arin2.invoice_id inner join sy_system sysy2 on arcsys2.system_id = sysy2.system_id arin2.invoice_date > dateadd(year, -1, getdate()) , arc2.customer_number = '300000' --and arin2.invoice_number = '204686' , arii2.[description] ('warranty credit') or arii2.[description] = ('warranty credit t') group arii2.amount, arii2.[description]
which returned following results not looking for.
-10155.00 -7294.90 -6362.50 -3100.00 -800.00
as on appreciated!
you getting multiple rows because of group by. remove line, , 1 total sum.
Comments
Post a Comment