正文

SQL之纵表转横表问题2011-03-04 10:25:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/1mi2/52272.html

分享到:

横表有这么四列,Id是主键, Id code1 code2 code3 111 aaa bbb ccc 纵表只有两列: ID code 111 aaa 111 bbb 111 ccc SQL模板1: select id,max(case when code='aaa' then code end) as code1,  max(case when code='bbb' then code end) as code2,  max(case when code='ccc' then code end) as code3  from tt group by id SQL模板2:  select id,max(case code when  'aaa' then code else null end) as code1,  max(case code when 'bbb' then code else null end) as code2,  max(case code when  'ccc' then code   else null end) as code3  from tt group by id

阅读(2358) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册