类别代码,类别名称(或项目名称),金额(或合计金额) 1,第一类,20。00 1,A项目,5.00 1,2,2,B项目,15.00 2,第二类,30.00 2,C项目,10.00 2,D项目,20.00 ------解决思路---------------------- with tmp as (select t1.name, t2.* from t1, t2 where t1.code = t2.ibcode) select ibcode, nvl(xmname, name), sum(money) from tmp t group by name, ibcode,rollup(xmname) order by ibcode,grouping(xmname) desc,xmname