sql - Like PIVOT but values not discrete -
a table lists multiple events each event has 4 attributes (columns), call them a, b, c, p
it simpleto pivot table columns a, b, c, p=1, p=2, p=3, etc.
however, need columns a, b, c, p<1, p<2, p<3, etc.
in other words, if row of "simple" way x, y, z, 7, 3, 5, 2 need x, y, z, 7, 10, 15, 17 because p less n less n+1.
i know can compute values (x, y, z, 7, 10, 15, 17), load them temporary table, , pivot that, maybe there's simple sql talents don't recognize immediately?
if matters, result end in ssrs.
if understand correctly, should work.
select a, b, c, sum(case when p < 1 1 else 0 end) p1, sum(case when p < 2 1 else 0 end) p2, sum(case when p < 3 1 else 0 end) p3, sum(case when p < 4 1 else 0 end) p4 events group a, b, c
this not dynamic. example, if have row in there p=4 not add row p<5. it's using strictly < , not <=.
Comments
Post a Comment