求好心的大神帮我优化下sql语句
postgresql吧
全部回复
仅看楼主
level 1
秋涩年华 楼主
楼主是个小程序员(渣渣一枚)
在公司用python进行开发(老实说这公司挺坑的)
写程序的过程中发现一个以前的人留下的sql语句(找不到人了,挺恼火的)
然后这个sql语句动不动就执行爆了。想找大神帮忙优化下!
select c.amt as zyfy,
d.amt as gzhcfy,
a.amt as sxf,
b.amt as kssfy,
xy.xysum as sxl
from org,ctct,mtzyjl left join
(select mtzyjl,sum(amt) as amt from Mtzyjlstuff group by mtzyjl) as c on c.mtzyjl=mtzyjl.iid left join
(select mtzyjl,sum(amt) as amt from Mtzyjlstuff,mtprod where Mtzyjlstuff.mtprod=mtprod.iid and mtprod.printtype=81 group by Mtzyjlstuff.mtzyjl) as d on d.mtzyjl=mtzyjl.iid left join
(select mtzyjl,sum(amt) as amt from Mtzyjlstuff,mtprod where Mtzyjlstuff.mtprod=mtprod.iid and mtprod.printtype=12 group by Mtzyjlstuff.mtzyjl) as a on a.mtzyjl=mtzyjl.iid left join
(select mtzyjl,sum(amt) as amt from Mtzyjlstuff,mtprod where mtzyjlstuff.mtprod=mtprod.iid and mtprod.Isksyp=1 group by Mtzyjlstuff.mtzyjl) as b on b.mtzyjl=mtzyjl.iid left join
(select count(mtxystockinfo.iid) as xysum,ZYH from mtxystockinfo,mtjcpx,mtsxsqd where mtxystockinfo.iid = mtjcpx.mtxystockinfo and mtjcpx.mtsxsqd=mtsxsqd.iid and yxks<>'' GROUP BY ZYH) as xy on xy.ZYH=mtzyjl.zyjlbah
where mtzyjl.iid in (29660,29461) order by ctct.ssn,org.b
bp
x
2016年08月19日 09点08分 1
1