sql - Combine data from multiple rows into 1 row, multiple columns -
this question has answer here:
- how pivot rows columns (custom pivoting) 6 answers
this isn't first time i've been faced type of problem , i've still yet figure out.
i'm trying pull records of employee , find races are. way data returned as:
emp # | race ------------- 1111 | white 1111 | asian
i in end:
emp # | white | black | hispanic | asian | indian | other --------------------------------------------------------- 1111 | y | n | n | y | n | n
i've attempted through cte's , pivot function, may have not had great understanding of how use pivot.
build dynamic sql that
select emp, case when max(case when race = 'white' 1 else 0 end) = 1 'y' else 'n' white, case when max(case when race = 'asian' 1 else 0 end) = 1 'y' else 'n' asian, case when max(case when race = 'black ' 1 else 0 end) = 1 'y' else 'n' black [yourtable] group emp
Comments
Post a Comment