oracle 列转行

select Monthno 月份, SUM(thismonthacttotal) "总活跃用户数", SUM(OneDayTotal) "1天", SUM(TwoFourDayTotal) "2-4天", SUM(FiveNineDayTotal) "5-9天", SUM(OneFourTimeTotal) "低级活跃", SUM(FiveNineTimeTotal) "中级活跃", SUM(MoreTenTimeTotal) "高级活跃" from VW_Activity_Stat where 1 = 1 and Monthno=201101 GROUP BY Monthno;

数据结果如下:

月份 总活跃用户数 1天 2-4天 5-9天 低级活跃 中级活跃 高级活跃 201101 32882523 21212935 9303626 1240819 16409668 8292009 8180846为给报表的图形提供数据,除了柱状图可以这样提供一行多列的数据. 当饼图的数据是单列多行.

如下

月份 类型, 人数

201101低级活跃 16409668

201101中级活跃 16409668

201101高级活跃 16409668


那么怎么把列转成行呢? 网上大把是把行转成多列.

select a.Monthno,b.fid, decode(b.fid,'低级活跃',a.lowerActive, '中级活跃',a.MideActive, '高级活跃',a.HightActive, ) as LevelActive, from ( select Monthno , SUM(thismonthacttotal) AllActiveUser, SUM(OneDayTotal) onedaytotal, SUM(TwoFourDayTotal) TwoFourDayTotal, SUM(FiveNineDayTotal) FiveNineDayTotal, SUM(OneFourTimeTotal) lowerActive, SUM(FiveNineTimeTotal) MideActive, SUM(MoreTenTimeTotal) HightActive from VW_Activity_Stat where 1 = 1 and Monthno=201101 GROUP BY Monthno ) a, ( select '低级活跃' fid from dual union all select '中级活跃' fid from dual union all select '高级活跃' fid from dual ) b

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值