select decode(grouping(DATA_ID), 1, '合计', DATA_ID) as DATA_ID,
sum(H1) as H1,
sum(H2) as H2
from (select DATA_ID, H1, H2
from TB_REPORT_f302050700
where DATA_ID between '20120206' and '20120213')
group by rollup(DATA_ID);
select decode(grouping(outid),1,'合計',outid) outid,name,sum(sumopfare),
sum(case when sumopfare>=50 then 100 else sumopfare*2 end)
from (select bc.outid,bc.name,
sum(t.opfare) sumopfare,
from rec_cust_acc t,base_customers bc
where t.acccode = 101 and t.customerid = bc.customerid
and t.opdt between
to_date(concat('2010-08-01',' 00:00:00'),'yyyy-mm-dd hh24:mi:ss')
and to_date(concat('2010-12-06',' 23:59:59'),'yyyy-mm-dd hh24:mi:ss')
group by bc.outid,bc.name,t.opfare)
group by rollup((outid,name))
order by outid,name;