MS-SQL分页not in 方法改进之使用Max\Min
2012-11-28 22:02
204 查看
先看下表中共有多少条数据:
一百二十多万条,呵呵。
sql语句:
分页效率一目了然!
两种方法的不同点之一就是计算第二个top中的值
not in 中计算公式为:
max\min中计算公式为:
pgNo为当前第几页,pgSize为每页几条数据。
一百二十多万条,呵呵。
sql语句:
declare @d datetime set @d = getdate() select top 10 ID,U_Name,U_Age,U_Sex,U_Address from Test1 where ID not in (select top 9990 ID from Test1 order by ID) order by ID select [not in方法升序分页执行花费时间(毫秒)]=datediff(ms,@d,getdate()) declare @s datetime set @s = getdate() select top 10 ID,U_Name,U_Age,U_Sex,U_Address from Test1 where ID >=(select max(ID) from (select top 9991 ID from test1 order by ID) as T) order by ID select [Max方法升序分页执行花费时间(毫秒)]=datediff(ms,@s,getdate()) declare @t datetime set @t = getdate() select top 10 ID,U_Name,U_Age,U_Sex,U_Address from Test1 where ID not in (select top 9990 ID from Test1 order by ID desc) order by ID desc select [not in方法降序分页执行花费时间(毫秒)]=datediff(ms,@t,getdate()) declare @q datetime set @q = getdate() select top 10 ID,U_Name,U_Age,U_Sex,U_Address from Test1 where ID <=(select min(ID) from (select top 9991 ID from Test1 order by ID desc) as T) order by ID desc select [Min方法降序分页执行花费时间(毫秒)]=datediff(ms,@q,getdate())
分页效率一目了然!
两种方法的不同点之一就是计算第二个top中的值
not in 中计算公式为:
pgSize * (pgNo - 1)
max\min中计算公式为:
((pgNo-1)*pgSize+1)
pgNo为当前第几页,pgSize为每页几条数据。
相关文章推荐
- MS-SQL分页not in 方法改进之使用row_number
- Math.min() / Math.max() 使用方法
- 学习总结--Css中最小宽度min-width和最大宽度max-width属性的使用方法
- 4、内置函数abs、all、any、min、max使用方法
- 常量,字段,构造方法 调试 ms 源代码 一个C#二维码图片识别的Demo 近期ASP.NET问题汇总及对应的解决办法 c# chart控件柱状图,改变柱子宽度 使用C#创建Windows服务 C#服务端判断客户端socket是否已断开的方法 线程 线程池 Task .NET 单元测试的利剑——模拟框架Moq
- 前面学习通过方法对代码进行改进,为什么要给方法使用静态呢?
- CSS3 响应式布局: 使用@media (min/max-width:***) 和@font-face及其兼容
- WM_GETMINMAXINFO消息的使用
- Java Collections的min和max方法
- LINQ当集合为空的时候,如何使用Max,Min,Sum等聚合函数?
- 使用Hibernate获取最大值(max)的三种方法
- ruby应用里添加zepto.min.js但是无法使用里面的方法
- Hibernate -- 使用Hibernate获取最大值(max)的三种方法(转)
- 在Ubuntu 10.04中文版下Qt编程,使用unixODBC和FreeTDS连接MS SQL Server 2005,并且中文不出现乱码的方法
- 当使用EasyUI时,需要的Field属性是子属性时候,除了formatter和修改jquery.easyui.min.js的方法
- EF 汇总函数使用注意事项Max()/Min()等
- ie6下使用min-height的方法
- Visual C++中min()和max()函数的使用
- [KinectWPF程序]1深度图像,使用WriteableBitmap对象改进Kinect图像显示&复杂的Kinect初始化方法
- 让IE6支持max-height又支持min-height方法