SqlServer的Unpivot列转行语句(n1,n2,n3,n4,n5,n6,n7,n8,n9)
select c.score,sum(c.ccount)
from (select b.n ,b.score,count(1) ccount
from (select unpriots.n,unpriots.score
from (select cdate,n1,n2,n3,n4,n5,n6,n7,n8,n9 from tb_test) a
unpivot
(score for n in (n1,n2,n3,n4,n5,n6,n7,n8,n9)) unpriots
) b
group by n,score
) c
group by score