oracle 关于union统计查询

liangfu 2013-10-29 09:52:55
select airline,
sum(saleprice) as saleprice,
sum(airporttax) as airporttax,
sum(oiltax) as oiltax,
sum(ticketnum) as ticketnum,
sum(voyagenum) as voyagenum,
(saleprice / s) as saleper
from tb_app_airlinesale_d
where data_date = '20130101'
and date_type = 't'
and ticketstatus = '0'
group by airline
union
select 'total',
sum(saleprice) as s,
sum(airporttax) as a,
sum(oiltax) as o,
sum(ticketnum) as t,
sum(voyagenum) as v,
'a'
from tb_app_airlinesale_d
where data_date = '20130101'
and date_type = 't'
and ticketstatus = '0'
group by 'total'

我想通过union新增一行合计,然后在新增一列,得到union上面的一个字段与下面对应字段的一个比值,用百分比显示
...全文
194 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
liangfu 2013-11-14
  • 打赏
  • 举报
回复
哎,我已经解决了,回复太慢了,但是还要谢谢你!
  • 打赏
  • 举报
回复
地址没给上连接。rullup使用 分析函数RATIO_TO_REPORT
  • 打赏
  • 举报
回复
对于楼主这个问题union连接,也可以直接用rullup。参考地址:http://blog.csdn.net/wanghai__/article/details/4817920 而百分比计算统计的话,可以用RATIO_TO_REPORT() OVER()分析函数。参考地址: http://blog.csdn.net/rfb0204421/article/details/7676008

17,078

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧