关于复杂行列转换的问题.急!

jsy2005 2006-10-24 09:15:29
有如下表

A B C D E
1 2 1 4 AA
2 3 1 2 BB


希望转换成如下形式

AA BB
A 1 2
B 2 3
C 1 1
D 4 2


请问如何实现
...全文
89 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
dawugui 2006-10-24
  • 打赏
  • 举报
回复
楼上正解
i9988 2006-10-24
  • 打赏
  • 举报
回复
select 'A' as E,max(case when E='AA' then a end) as AA,max(case when E='BB' then a end) as BB from tablename
union all
select 'B' as E,max(case when E='AA' then b end) as AA,max(case when E='BB' then b end) as BB from tablename
union all
select 'C' as E,max(case when E='AA' then c end) as AA,max(case when E='BB' then c end) as BB from tablename
union all
select 'D' as E,max(case when E='AA' then d end) as AA,max(case when E='BB' then d end) as BB from tablename

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧