请问下面这条语句有什么办法可以优化下:select code,descp,sum(money) sum_money
from ( select a.code,b.descp,sum(c.money*b.acount)money from table1 a,table2 b,table3 c
where a.code=b.code and b.descp=c.descp and .. group by a.code,b.descp
union all
select e.code,b.descp,sum(f.money*b.acount)money from table4 e,table5 f,table2 b
where e.code=b.code and b.descp=f.descp and .. group by e.code,b.descp
union all
select g.code,b.descp,sum(h.money*b.acount)money from table7 g,table8 h,table2 b
where g.code=b.code and b.descp=h.descp and .. group by e.code,b.descp
)group by code,descp
from ( select a.code,b.descp,sum(c.money*b.acount)money from table1 a,table2 b,table3 c
where a.code=b.code and b.descp=c.descp and .. group by a.code,b.descp
union all
select e.code,b.descp,sum(f.money*b.acount)money from table4 e,table5 f,table2 b
where e.code=b.code and b.descp=f.descp and .. group by e.code,b.descp
union all
select g.code,b.descp,sum(h.money*b.acount)money from table7 g,table8 h,table2 b
where g.code=b.code and b.descp=h.descp and .. group by e.code,b.descp
)group by code,descp
把你的表结构,业务逻辑说一下
这样才知道是否需要通过UNION来实现
from子句,数据量小的表放最后。里面的group by,a.code,e.code,g.code可以改成b.code