--■■■分析関数を使う方法■■■
select distinct 区分,
sum(金額) over(partition by 区分,case when 区分 in(6,7) then RowNum end) as 金額
from (select 1 as 区分,500 as 金額 from dual
union select 1,300 from dual
union select 1,300 from dual
union select 2,450 from dual
union select 3,550 from dual
union select 6,100 from dual
union select 6,200 from dual
union select 7,320 from dual
union select 7,500 from dual)
order by 区分,金額;
--■■■グループ化する方法■■■
select 区分,sum(金額) as 金額
from (select 1 as 区分,500 as 金額 from dual
union select 1,300 from dual
union select 1,300 from dual
union select 2,450 from dual
union select 3,550 from dual
union select 6,100 from dual
union select 6,200 from dual
union select 7,320 from dual
union select 7,500 from dual)
group by 区分,case when 区分 in(6,7) then RowNum end
order by 区分,金額;