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上面的一个字段与下面对应字段的一个比值,用百分比显示
------解决方案--------------------
对于楼主这个问题union连接,也可以直接用rullup。参考地址:http://blog.csdn.net/wanghai__/article/details/4817920
而百分比计算统计的话,可以用RATIO_TO_REPORT() OVER()分析函数。参考地址:
http://blog.csdn.net/rfb0204421/article/details/7676008
------解决方案--------------------
地址没给上连接。rullup使用
分析函数RATIO_TO_REPORT