楼主是用sql server中用到:
CUBE 运算符生成的结果集是多维数据集。多维数据集是事实数据的扩展,事实数据即记录个别事件的数据。扩展建立在用户打算分析的列上。这些列被称为维。多维数据集是一个结果集,其中包含了各维度的所有可能组合的交叉表格。select id,sal1,sal2 from tab1
union
select id,sum(sal1),sum(sal2) from tab1 group by id
union
select null,sum(sql1),sum(sal2) from tab1
CUBE 运算符生成的结果集是多维数据集。多维数据集是事实数据的扩展,事实数据即记录个别事件的数据。扩展建立在用户打算分析的列上。这些列被称为维。多维数据集是一个结果集,其中包含了各维度的所有可能组合的交叉表格。select id,sal1,sal2 from tab1
union
select id,sum(sal1),sum(sal2) from tab1 group by id
union
select null,sum(sql1),sum(sal2) from tab1
看看
select (case when t.fund_code is null then ' '
else t.recevied_date end) recevied_date,
(case when t.fund_code is null and t.recevied_date is null then '总计'
when t.fund_code is null then '合计'
else min(tt.fund_name)||to_char(to_date(min(t.trade_date),'yyyymmdd'),'yyyy-mm-dd')||'日交易' end) last_date,
sum(decode(t.operation_flag,'1',t.recevied_money)),
sum(decode(t.operation_flag,'1',0,t.recevied_money)),
sum(decode(t.operation_flag,'1',t.recevied_money))-sum(decode(t.operation_flag,'1',0,t.recevied_money)),
(case when t.fund_code is null then '1' else '0' end) BOLD
from fundrecevied_book t,
(select t0.fund_code fund_code,
t1.fund_name fund_name
from par_fund_team t0,par_fund t1
where t0.big_fund_code='PX_fundcode'
and t1.fund_code=t0.fund_code
and substr(t1.fund_kind,1,1)='2') tt
where t.fund_code=tt.fund_code
and t.recevied_date between 'PX_startdate' AND 'PX_enddate'
and t.operation_flag in ('1','2')
group by rollup(t.recevied_date,t.fund_code)
select a,b,sum(c) from xxx group by rollup(a,b);select a,b,sum(c) from xxx group by cube(a,b);Oracle817以上调试通过