select "种类", sum(case when "子类" = '1' then 1 else 0 end) as "子类1次数", sum(case when "子类" = '2' then 1 else 0 end) as "子类1次数" from tbl group by "种类";
with t as( select 'A' tp , 'a1' stp, 50 amount from dual union all select 'A' tp , 'a2' stp, 60 amount from dual union all select 'A' tp , 'a2' stp, 70 amount from dual union all select 'B' tp , 'b1' stp, 80 amount from dual union all select 'B' tp , 'b1' stp, 90 amount from dual )select t.tp,t.stp,sum(t.amount),count(1) from t group by t.tp,t.stp order by t.tp,t.stp
select Category,SubCategory,sum(decode(SubCategory,'1', 1,'2',1,0)) SumSubCategory from tbl group by Category,SubCategory;
select "种类",
sum(case when "子类" = '1' then 1 else 0 end) as "子类1次数",
sum(case when "子类" = '2' then 1 else 0 end) as "子类1次数"
from tbl
group by "种类";
with t as(
select 'A' tp , 'a1' stp, 50 amount from dual
union all
select 'A' tp , 'a2' stp, 60 amount from dual
union all
select 'A' tp , 'a2' stp, 70 amount from dual
union all
select 'B' tp , 'b1' stp, 80 amount from dual
union all
select 'B' tp , 'b1' stp, 90 amount from dual
)select t.tp,t.stp,sum(t.amount),count(1)
from t
group by t.tp,t.stp
order by t.tp,t.stp
select Category,SubCategory,sum(decode(SubCategory,'1', 1,'2',1,0)) SumSubCategory
from tbl
group by Category,SubCategory;