【发布时间】:2012-07-11 13:41:34
【问题描述】:
这是表结构:
Election
ElectionId ElectionName
1 12P
2 11G
History
ElectionId VoterId HowVoted
1 1 Rep
2 2 Dem
1 2 Non
Voter
VoterId VoterName
1 Bill Smith
2 John Hearst
我想要这样的输出:
VoterName 12P 11P note: Election names change so need to be pivoted dynamically
Bill Smith Rep Null
John Hearst Non Dem
我基本上需要将 ElectionNames 转为 Column Names,然后显示选民如何在行中投票。建议?谢谢!
【问题讨论】:
-
请显示样本数据和所需结果。另外,请使用
{}正确突出代码示例而不是<br>标签。 -
你没有显示你尝试了什么?
标签: sql-server tsql sql-server-2005 pivot