sql server 行转列 要注意的问题 pivot
select * from (
select mvqr.VoteQuestionId,mvqr.AnswerSolution from JY_MemberVoteQuestionRef as mvqr
where mvqr.MemberVoteId in (select MemberVoteId from JY_MemberVote where VoteId='166')
) as t
pivot (max(t.AnswerSolution) for t.VoteQuestionId
in
( [755],[762],[764],[770],[772],[754],[757],[769],[771] )) as puv
select mvqr.VoteQuestionId,mvqr.AnswerSolution from JY_MemberVoteQuestionRef as mvqr
where mvqr.MemberVoteId in (select MemberVoteId from JY_MemberVote where VoteId='166')
) as t
pivot (max(t.AnswerSolution) for t.VoteQuestionId
in
( [755],[762],[764],[770],[772],[754],[757],[769],[771] )) as puv
应用格式 : pivot ( 列2 for 列1 in ( 所有列名) )
注意点 1 : 列2 要 max() 或 min() 或 sum()
注意点2 : 所有列名 要 是 唯一的,不可重复 并且 要用 [] 包裹 例: [755]