如何用SELECT实现
我有一个表数据:
ID SEQ TYPE VALUE
1 1 T1 1
1 2 T2 1
1 3 T3 4
1 4 T2 1
2 1 T1 4
2 2 T2 5
...
结果为
ID T1 T2 T3
1 1 2 4
2 4 5 0
...
同一ID把所有TYPE值按列显示,若有相同,则相加。
望高手指教!
[解决办法]
- SQL code
with tt as( select 1 id, 1 seq, 'T1' type, 1 value from dual union all select 1 id, 2 seq, 'T2' type, 1 value from dual union all select 1 id, 3 seq, 'T3' type, 4 value from dual union all select 1 id, 4 seq, 'T2' type, 1 value from dual union all select 2 id, 1 seq, 'T1' type, 4 value from dual union all select 2 id, 2 seq, 'T2' type, 5 value from dual) SELECT id, SUM(decode(TYPE, 'T1', VALUE, 0)) t1, SUM(decode(TYPE, 'T2', VALUE, 0)) T2, SUM(decode(TYPE, 'T3', VALUE, 0)) T3 FROM tt GROUP BY id;
[解决办法]
[解决办法]
俺不会啊
[解决办法]
行列转换,太常见了。
不固定列的,可以动态拼SQL来实现
[解决办法]
动态sql 明天上班写个
[解决办法]
顶一下
oracle QQ群:54775466
欢迎您的到来
大家一起探讨。
[解决办法]
比较经典
http://topic.csdn.net/u/20100109/13/6a10c168-f190-4766-b838-adbf03c4ac7b.html