17,086
社区成员
发帖
与我相关
我的任务
分享
with t1 as
(select 'A' c1, 200 c2
from dual
union all
select 'A' c1, 100 c2
from dual
union all
select 'A' c1, 200 c2
from dual
union all
select 'B' c1, 100 c2
from dual
union all
select 'B' c1, 100 c2 from dual)
select decode(t3.rn, null, '汇总', t3.c1) as c1, t3.s as c2
from (select t2.rn, t2.c1, sum(t2.c2) s
from (select t1.*, rownum rn from t1) t2
group by cube(t2.rn, t2.c1)) t3
where t3.c1 is not null
with t1 as
(
select 'A' c1,200 c2 from dual
union all
select 'A' c1,100 c2 from dual
union all
select 'A' c1,200 c2 from dual
union all
select 'B' c1,100 c2 from dual
union all
select 'B' c1,100 c2 from dual
)
select nvl(c1,c3) c1,nvl(c2,c4) c2 from t1 full join
(select '汇总'||c1 c3,sum(c2) c4 from t1 group by c1) t
on c1=c3
order by c1
结果显示为:
C1 C2
----- ----------------------
A 200
A 100
A 200
B 100
B 100
汇总A 500
汇总B 200
7 rows selected