大佬教程收集整理的这篇文章主要介绍了SQL Server 性能调优之查询从20秒至2秒的处理方法,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
需求很简单,就是需要查询一个报表,只有1个表,数据量大约60万左右,但是中间有些逻辑。
先说明一下服务器配置情况:1核cpu、2GB内存、机械硬盘、sqlserver 2008 R2、Windows Server2008 R2 SP1和阿里云的服务器,简单说就是阿里云最差的服务器。
非常简单的一张表,这次不讨论数据冗余和表字段的设计,如是否可以把Project和Baojian提出成一个表等等,这个是原始表结构,这个目前是没有办法改变的。
0 then 1 else -0.5 end)))@H_673_27@ 0 then 1 else -0.5 end))) end as sc from ( SELEct * from ( SELEct a.Projectnumber,a.ProjectName,a.baojiannumber,a.baojiAnname,a.ToubiaoPerson,sum(UnitPricE) as sumPrice,b.price as avgPrice,((sum(UnitPricE)-b.pricE)/NULLIF(b.price,0)*100) as p,sum(case when UnitPrice>b.price then b.price else UnitPrice end )as pprice,sum(case when UnitPrice>MaxPrice then 1 else 0 end ) as countChao from ToubiaoDetailTest1 a join ( SELEct Projectnumber,ProjectName,Baojiannumber,BaojiAnname,avg(pricE) as price from( SELECT * from( SELEct Projectnumber,ToubiaoPerson,SUM(UnitPricE) as price,sum(case when UnitPrice>MaxPrice then 1 else 0 end ) as countChao from ToubiaoDetailTest1 group BY Projectnumber,ToubiaoPerson ) tt where tt.countChao = 0 ) t group by Projectnumber,BaojiAnname ) b on a.Projectnumber=b.Projectnumber and a.ProjectName=b.ProjectName and a.baojiannumber=b.baojiannumber and a.baojiAnname=b.baojiAnname group by a.baojiannumber,a.Projectnumber,b.price ) tt where tt.countChao=0 ) a ) b ) t order by rank =30>
以上是大佬教程为你收集整理的SQL Server 性能调优之查询从20秒至2秒的处理方法全部内容,希望文章能够帮你解决SQL Server 性能调优之查询从20秒至2秒的处理方法所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。