Friday, 15 May 2015

sql - Need to count two separate values in one column -



sql - Need to count two separate values in one column -

i'm trying sums of 2 separate values appear in 1 row, per unique id. i've tried couple routes still can't appear in 1 row. i've tried few different ways of using case statements , i've tried using on partitions, well, no avail.

here query far:

select distinct id_num, sum(case when isnull(sch.subterm_cde,0) '%n' 1 else 0 end) 'total_n', sum(case when isnull(sch.subterm_cde,0) '%t' 1 else 0 end) 'total_t' student_crs_hist sch sch.end_dte > getdate() grouping sch.id_num, sch.subterm_cde order id_num

you right, grouping column:

select id_num, sum(case when sch.subterm_cde '%n' 1 else 0 end) total_n, sum(case when sch.subterm_cde '%t' 1 else 0 end) total_t student_crs_hist sch sch.end_dte > getdate() grouping sch.id_num -- shouldn't grouping subterm_cde order id_num

sql sql-server count

No comments:

Post a Comment