sql列转行问题!

lubin1119 2006-12-21 09:52:26
有一个表:
no. id code value
1 100 abc 111
2 100 edf 222
3 100 ghi 333

怎样变成
id abc edf ghi
100 111 222 333

请大家帮助!
...全文
246 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
penglewen 2006-12-22
  • 打赏
  • 举报
回复
select id ,sum(case code when 'abc' then cast(value as int) end) as [abc],
sum(case code when 'edf' then cast( value as int) end) as [edf],
sum(case code when 'ghi' then cast (value as int) end) as [ghi]
from ctest
group by id
gd4134 2006-12-22
  • 打赏
  • 举报
回复
看不明白。。。

7,388

社区成员

发帖
与我相关
我的任务
社区描述
其他数据库开发 数据仓库
社区管理员
  • 数据仓库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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