sql - PIVOT query convert to group by for SSRS -
how change following pivot query group by?
select comb_id , [orgunit] , [time] , [gender] , [jobcategory] , [ethnicity] , [gradegroup] , [regiongeo] , [emplclass] , operatorid , seq_id , sequance_name , listid (select c.comb_id , dim_name , v.operatorid ,v.seq_id , v.listid , dim_value , s.sequance_name gmt_combinationsflat c join gmt_valuesflat v on c.comb_id = v.comb_id join gmt_rangeseq s on v.seq_id = s.seq_id join gmt_dimensions d on c.dim_id = d.dim_id c.kpi_id = 9 , c.last = 1) p pivot (max(dim_value) dim_name in ( [orgunit ] , [time ] , [gender ] , [jobcategory ] , [ethnicity ] , [gradegroup ] , [regiongeo ] , [emplclass ] ) ) pvtt
i have tried changing below. not sure column should put max groupby.
select c.comb_id, [orgunit ], [time ], [gender ], [jobcategory ], [ethnicity ], [gradegroup ], [regiongeo ], [emplclass ] , operatorid, seq_id, sequance_name, listid gmt_combinationsflat c join gmt_valuesflat v on c.comb_id = v.comb_id join gmt_rangeseq s on v.seq_id = s.seq_id join gmt_dimensions d on c.dim_id = d.dim_id c.kpi_id = 9 , c.last = 1 group comb_id,[orgunit ], [time ], [gender ], [jobcategory ], [ethnicity ], [gradegroup ], [regiongeo ], [emplclass ]
is equivalent to:
select c.comb_id, v.operatorid, v.seq_id, v.listid, s.sequance_name, max(case when dim_name = 'orgunit' dim_value end) [orgunit], max(case when dim_name = 'time' dim_value end) [time] .... gmt_combinationsflat c join gmt_valuesflat v on c.comb_id = v.comb_id join gmt_rangeseq s on v.seq_id = s.seq_id join gmt_dimensions d on c.dim_id = d.dim_id c.kpi_id = 9 , c.last = 1 group c.comb_id, v.operatorid, v.seq_id, v.listid, s.sequance_name
Comments
Post a Comment