这种情况 还是考虑union all吧 select '1年' y,sum(1年) from tb union all select '2年' y,sum(2年) from tb ...
如果是oracle 11g,可以用pivot,unpivot函数with t as (select 1 as "1year", 2 as "2year", 3 as "3year" from dual union all select 4 as "1year", 5 as "2year", 6 as "3year" from dual) select year, sum(counts) from (select * from t unpivot(counts for year in("1year", "2year", "3year"))) group by year order by 1;
select '1年' y,sum(1年) from tb
union all
select '2年' y,sum(2年) from tb
...
(select 1 as "1year", 2 as "2year", 3 as "3year"
from dual
union all
select 4 as "1year", 5 as "2year", 6 as "3year" from dual)
select year, sum(counts)
from (select *
from t unpivot(counts for year in("1year", "2year", "3year")))
group by year
order by 1;