sql - performing multiple separate sums with separate filters on a table -
i have table amount column reference field , id column. need sum amount based on different combinations of id's each reference. there 9 different combinations in total need insert separate table.
the best way i've found use cursor , each sum separately, assign amount variable , update table each reference , each combination.
hope makes sense!
what hoping find out - there better way it?
thanks.
you like:
select sum(case when (id = 9) val else 0 end) conditionalsum dbo.table
you can have many of sums different conditions in 1 query.