sql server - sql pivot table with strings -
i'm using sql 2008 , trying pivot data. sql fiddle
i have tried can't figure out. i'd take data , have appear this.
i put i've tried nothing run , can't both examid , score , pivot rest.
i've tried simple this
select * dbo.results pivot (max(answer) examid in ([19966], [19969]) ) p
but returns nulls. anyway great. shannon
you can use @bluefeet's answer, in order match expected output, need change sample data well:
create table results ( examid int , score int , bank int , answer char(1) ); insert results ( examid, score, bank, answer ) values ( 1, 70, 15, 'a' ), ( 1, 70, 16, 'a' ), ( 1, 70, 17, 'b' ), ( 1, 70, 18, 'd' ), ( 1, 70, 19, 'c' ), ( 2, 81, 15, 'b' ), ( 2, 81, 16, 'd' ), ( 2, 81, 17, 'c' ), ( 2, 81, 18, 'c' ), ( 2, 81, 19, 'c' );
pivot query:
select * results pivot ( max(answer) bank in ([15], [16], [17], [18], [19]) ) piv
Comments
Post a Comment