求sql语句优化
select invent.cDepotId,invent.cprodid
,case when in_iQuantity is null then 0 else in_iQuantity end in_iQuantity
,case when in_iSuCentiare is null then 0 else in_iSuCentiare end in_iSuCentiare
,case when in_iSuAmt is null then 0 else in_iSuAmt end in_iSuAmt
,case when ou_iQuanTity is null then 0 else ou_iQuanTity end ou_iQuanTity
,case when ou_iSuCentiare is null then 0 else ou_iSuCentiare end ou_iSuCentiare
from (
select depot.cDepotId,cDepotName,invent.cClassId,cProdid,cProdName,iCentiare,cSpecif,cUnit
from invent FULL OUTER JOIN depot on invent.cProdid<>depot.cDepotId
)invent left join (
select cDepotId,paperlog.cProdId,sum(iQuanTity)in_iQuanTity,sum(iSuCentiare)in_iSuCentiare,sum(iSuAmt)in_iSuAmt
from paperlog,papClass
where paperlog.cPapcType=papClass.cPapcType and paperlog.iyear=2012 and paperlog.imonth=7 and papClass.cPapcName='入库'
group by cDepotId,cProdId) inPaperlog on invent.cProdId=inPaperlog.cProdid and invent.cDepotId=inPaperlog.cDepotId
left join (
select cDepotId,paperlog.cProdId,sum(iQuanTity)ou_iQuanTity,sum(iSuCentiare)ou_iSuCentiare
from paperlog,papClass
where paperlog.cPapcType=papClass.cPapcType and paperlog.iyear=2012 and paperlog.imonth=7 and papClass.cPapcName='出库'
group by cDepotId,cProdId
)ouPaperlog on invent.cProdId=ouPaperlog.cProdId and invent.cDepotId=ouPaperlog.cDepotId
where in_iQuantity<>0 or in_iSuCentiare<>0 or in_iSuAmt<>0 or ou_iQuanTity<>0 or ou_iSuCentiare<>0
order by invent.cprodid,invent.cDepotId
这个语句,执行不了,Sql服务器好像死循环了
如果把
where in_iQuantity<>0 or in_iSuCentiare<>0 or in_iSuAmt<>0 or ou_iQuanTity<>0 or ou_iSuCentiare<>0
这句给删除了,查询出来的记录也才80000多条
为什么会这样呢?
求师兄师姐给指点一下,谢谢!
...全文
相关推荐
数据库性能优化之SQL语句优化
数据库性能优化之SQL语句优化数据库性能优化之SQL语句优化数据库性能优化之SQL语句优化数据库性能优化之SQL语句优化
SQL SERVER 的SQL语句优化方式小结
千辛万苦,终于把数据库服务器的CPU从超过50%(开5个程序线程)乃至100%(开10个程序线程)降低到了5%。摸索到了一些门道,总结一下
必须掌握的30种SQL语句优化
便于Java入门人员交流学习。可以深刻理解该语言的常用API。帮助初学者尽快入门。
SQL语句的优化学习总结
精通SQL语句的优化学习总结精通SQL语句的优化学习总结
sql语句优化之用EXISTS替代IN、用NOT EXISTS替代NOT IN的语句
sql语句优化之用EXISTS替代IN、用NOT EXISTS替代NOT IN的语句


