回到目录

数据分页是这个经常说的东西,无论在WEBForm还是WinForm中它都会被单独拿出来,或者是公用组件,或者是公用类库,反正对于数据分页这个东西,总是我们关注的一个话题,但事实上,数据分页归根结底是数据库的东西,更直接的说,它是数据表的范畴,对于一个SQL请求来说,你要取数据,要取多少条,从哪条开始取,这事实上就是分页实现的原理。

SQL更新到2005版之后,为开发者提供了不少函数,ROW_NUMBER() OVER ()就是其中之一,它可以为你的结果集生成一个行号,并可以快速的主位到第几条数据。

MSDN上对它的应用

USE AdventureWorks2012;
GO
SELECT ROW_NUMBER() OVER(ORDER BY SalesYTD DESC) AS Row,
FirstName, LastName, ROUND(SalesYTD,2,1) AS "Sales YTD"
FROM Sales.vSalesPerson
WHERE TerritoryName IS NOT NULL AND SalesYTD <> 0;

结果会把集合加上行号,如下:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZQAAAEZCAIAAAA/iUTxAAAgAElEQVR4nO2d3YGDIBCEU5cFUY/V2IzF5B5MdGFn+VFzsjrf052i4gIjoExeb0IIccjr6gwQQsgeKF6EEJdQvAghLqF4EUJc0qt4zePweoXp6mwQch1TeC2wIUDqxWuN5Ov1Gsb5nMvLk0ZldEi85nGIj52CyLTa2xPzOBwLruN7fwrzOKAqn0ndXmTzOEStdPl/ElfeWnLUCD3Vjibx+kQjDcwBpvCLaKEGPAyDyH63RfQT8XJy74+gufHsLTJ5ofSicbPbWrazAc8e8YriKR4jYXobjccsLChesLc8hVcY12uBqy8XmdNnyzDOnzxM45DkUD5yli3zOAzjuPRVxiCulN7mr4DipfN5y3t/BIZ44SL+HhBtgcWhKoM8UjVBU7xO7Zn8nD3iNQVR35W6f9N9ApR/cEQ91ihm6XFT2BKssTc6boaAzksLRjn6bvs+eT5X+0qJvE5WjA9T6HmJvN/v3h/CR2esQKZFlPyPi8OoDFN4LY/8ZGdGvDyV8a45L2MGZQnJp9JPYRiG7V/7pIayAfHSKT/1wGqO8uBPQ1xapRCA+IH33fc54JP5tEvz7+KFZiXud++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m8jBt+pEoIeQIUL0KISyhehBCXULwIIS75AwRETZp+mWB9AAAAAElFTkSuQmCC" alt="" />

在项目中,分页功能的应用,代码如下:

SELECT  *FROM (SELECT ROW_NUMBER() OVER ( ORDER BY a.orderid ) AS row ,*
FROM dbo.Order_Info_View AS a
where CONVERT(CHAR(7),a.buytime,20)='2010-04'and a.agentid=3455) AS b
WHERE b.row BETWEEN 1 AND 20

事实上,把上面的代码改一下,就可以方例的实现对某页数据的统计了,呵呵

SELECT  sum(totalfee)
FROM (SELECT ROW_NUMBER() OVER ( ORDER BY a.orderid ) AS row ,*
FROM dbo.Order_Info_View AS a
where CONVERT(CHAR(7),a.buytime,20)='2010-04'and a.agentid=3455) AS b
WHERE b.row BETWEEN 1 AND 20

回到目录

知方可补不足~SQL2005使用ROW_NUMBER() OVER()进行数据分页的更多相关文章

  1. 知方可补不足~Sqlserver发布订阅与sql事务的关系

    回到目录 前几讲说了一下通过sqlserver的发布与订阅来实现数据的同步,再通过EF这个ORM架构最终实现架构系统的读写分离,而在使用发布与订阅来实现数据同步时,需要我们注意几点,那就是当操作被使用 ...

  2. 知方可补不足~用SqlProfiler来监视数据库死锁

    回到目录 关于锁的相关知识,大家可以看我的这篇文章<知方可补不足~Sqlserver中的几把锁和.net中的事务级别> 死锁我想大家都知道,当一个对话(线程)占用一个资源时,别一个线程也同 ...

  3. 【转载】Sqlserver数据库中无自增Id的情况下使用ROW_NUMBER()函数进行数据分页

    在Sqlserver数据库中,如果查询表中含有自增长Id列,一般会采用select Top的方式来数据的分页操作.而实际上很多数据表设计的时候,不一定含有自增长Id列,那么数据库没有Id自增列的时候要 ...

  4. 知方可补不足~sqlserver中使用ROW_NUMBER进行的快速分页

    回到目录 这个在SQL2005之后最见的一种分页方式,也是Linq默认生成的执行分页的方法(skip,take),当然在性能上小数量没有问题,在数据达到百万时会很慢,这是我们要清楚的,有时我们在LIN ...

  5. 知方可补不足~row_number,rank,dense_rank,ntile排名函数的用法

    回到目录 这篇文章介绍SQL中4个很有意思的函数,我称它的行标函数,它们是row_number,rank,dense_rank和ntile,下面分别进行介绍. 一 row_number:它为数据表加一 ...

  6. 知方可补不足~sqlserver中触发器的使用

    回到目录 触发器在过去的10年中,即存储过程和ado.net称霸江湖期间是那么的重要,而现在,trigger显得不是那么必要的,我们很少将复杂的业务写在SQL里,当然也会没有机会写到trigger里了 ...

  7. 知方可补不足~sqlserver中使用sp_who查看sql的进程

    回到目录 在SQLSERVER中每个会话,即每个查询分析器窗口都会产生一个SQL进程,对于那些持续时间短的进程,它们转瞬即失,而对于持续时间比较长的,我们需要希望查看它的运行状态,就可以借助SQL提供 ...

  8. 知方可补不足~SQL2008中的发布与订阅模式

    回到目录 作用:完成数据库与数据库的数据同步 原理:源数据库发布需要同时的表,存储过程,或者函数:目标数据库去订阅它,当源发生变化时,目标数据库自己同步,注意,由于这个过程是SQL自动完成的,所以要求 ...

  9. 知方可补不足~SQL2008中的发布与订阅模式~续

    回到目录 上一回介绍了如何在sql2008中建立一个数据库的发布者,今天来说一下如何建立一个订阅者,其实订阅者也是一个数据库,而这个数据库是和发布者的数据结构相同的库,它们之间通过SQL代理进行数据上 ...

随机推荐

  1. jQuery基础_1

    jQuery事件的因果关系是怎么样的一个格式: $("button").click(function(){ }); [正式接触jQuery] (1)jQuery的书写步骤: 1.引 ...

  2. Linux下连接MSSQL之安装FreeTDS

    $ tsql -H MSSQL服务器服务IP -p 1433 -U MSSQL服务器登陆帐号 -P MSSQL服务器登陆密码http://www.cnblogs.com/ilovexiao/p/355 ...

  3. lua 快速排序

    function partion(arr, left, right) local tmp = arr[left] while left < right do while left < ri ...

  4. zabbix中文乱码解决方法

    将windows下的字体文件Fonts\simkai.ttf上传到zabbix的WEB目录下的fonts目录下 修改zabbix的PHP配置 将原来的DejaVuSans更改成simkai vim / ...

  5. 64位系统 IIS中应用程序池设置导致 访问数据库错误

    64 位操作系统不支持Microsoft OLE DB Provider for Jet驱动程序,也不支持更早的Microsoft Access Driver (*.mdb)方式连接.导致程序里面的数 ...

  6. wp学习计划!

    对wp兴趣很大,可真正学习时,目的性就很不明确了,其实这有两大问题阻碍着,一是自身的基础还不够扎实,二是学习资料不好找,前者只能慢慢积累,而后者却是可以改变的,现在我的主阵营是channel 9上的w ...

  7. HDU1575Tr A(矩阵相乘与快速幂)

    Tr A hdu1575 就是一个快速幂的应用: 只要知道怎么求矩阵相乘!!(比赛就知道会超时,就是没想到快速幂!!!) #include<iostream> #include<st ...

  8. opencl初体验

    总结一下,opencl的步骤差不多是这些 先要获取平台的id clGetPlatformIDs(nPlatforms, platform_id, &num_of_platforms) 然后获取 ...

  9. [leetcode 25]Reverse Nodes in k-Group

    1 题目: Given a linked list, reverse the nodes of a linked list k at a time and return its modified li ...

  10. Android度量单位说明(DIP,DP,PX,SP) (转帖)

    (一)概念 dip: device independent pixels(设备独立像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支持WVGA.HVGA和QVGA 推荐使用这个,不 ...