oracle 列转行的统计
原:
perid oper_type
1 2
2 1
3 3
4 3
5 2
需要的效果:
perid 合计1 合计2 合计3
1 0 1 0
2 1 0 0
。。。。。
select sum(a) 合计1,sum(b) 合计2,sum(c) 合计3 from
(
select oper_type
,decode(oper_type,'1',1,0) a
,decode(oper_type,'2',1,0) b
,decode(oper_type,'3',1,0) c
from man_operlog where to_char(oper_time,'yyyy-MM')= '2010-10')
group by perid
/*order by oper_type*/