如何优化如下SQL语句?
如何优化如下SQL语句呢
当数据达到上万条后,动不动就五十多秒啊
SELECT ProductName , Total=(SELECT sum(ProductNumber) FROM ProductInfo WHERE PID <TBL.PID)+ ProductNumber FROM ProductInfo TBL
------解决方案--------------------SELECT TBL.ProductName , Total=sum(b.ProductNumber)+TBL.ProductNumber FROM ProductInfo TBL,ProductInfo as b WHERE b.PID <TBL.PID group by TBL.ProductName ,TBL.ProductNumber