oracle sql语句转置表

[复制链接]
查看11 | 回复1 | 2010-1-7 10:48:16 | 显示全部楼层 |阅读模式
select col1,col2,sum(decode(col3,'X',col4)) X,sum(decode(col3,'Y',col4)) Y,sum(decode(col3,'Z',col4)) Zfrom tablenamegroup by col1,col2
回复

使用道具 举报

千问 | 2010-1-7 10:48:16 | 显示全部楼层
select a.列1,a.列2,a.列4 as X,null as Y,null as Z from 表1 as a where a.列3 = 'X'union allselect b.列1,b.列2,null as X,b.列4 as Y,null as Z from 表1 as b where b.列3 = 'Y'union allselect c.列1,c.列2,null as X,null as Y,c.列4 as Z from 表1 as c where c.列3 = 'Z'
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行