日期:2014-05-17 浏览次数:20680 次
SELECT * FROM AA UNION ALL select '' ID,SUM(NUMBER),NAME from aa GROUP BY CUBE(NAME)
------解决方案--------------------
rollup
------解决方案--------------------
With t As ( select 1 Id,10 numb, 'i' Name From dual Union All select 2 Id,20 numb, 'i' Name From dual Union All select 3 Id,30 numb, 'i' Name From dual Union All select 4 Id,10 numb, 'j' Name From dual Union All select 5 Id,20 numb, 'j' Name From dual Union All select 6 Id,30 numb, 'j' Name From dual ) SELECT id, SUM(numb) numb, decode(grouping_id(id, NAME), 3, '合计', 2, '小記', NAME) NAME FROM t GROUP BY ROLLUP(NAME, Id)