语句优化的问题!!!!

wanglaibing 2009-12-18 11:09:51
请问下面这条语句有什么办法可以优化下:

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
...全文
94 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hebo2005 2009-12-18
  • 打赏
  • 举报
回复
不清楚你的业务逻辑,光看语句看不出优化的地方
把你的表结构,业务逻辑说一下
这样才知道是否需要通过UNION来实现
wanglaibing 2009-12-18
  • 打赏
  • 举报
回复
主要是统计出三张不同表里面的money然后再合计。而这三张表里面有些信息又要到其它的表里面取出。
crazylaa 2009-12-18
  • 打赏
  • 举报
回复
table1,3与table4,5与table7,8有没有关联啊,没有关联估计没法不union all。。
from子句,数据量小的表放最后。里面的group by,a.code,e.code,g.code可以改成b.code

3,494

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧