当前位置: 代码迷 >> SQL >> SQL 单表多条记要分组查询分页代码
  详细解决方案

SQL 单表多条记要分组查询分页代码

热度:82   发布时间:2016-05-05 15:10:41.0
SQL 单表多条记录分组查询分页代码

SQL表结构如下图:


SQL 分页语句:

[sql]?view plaincopy
  1. <span?style="font-size:16px;">SELECT?TOP?5?*,(select?count(*)???inum?from???
  2. (select?distinct??AreaID,AreaTypeID,lifeYear,[State],RelatedID?from?MonitorBaseEnterInfo?where??1=1)?i?)?as?CountNum??FROM???????
  3. ??(SELECT?ROW_NUMBER()?OVER?(?order?by?lifeYear?desc)?AS?RowNumber,*?FROM?(select?distinct??AreaID,AreaTypeID,lifeYear,[State],RelatedID???
  4. ????from?MonitorBaseEnterInfo?where??1=1?)?mm??)?A??
  5. ?????WHERE?RowNumber?>?5?*(1-1)</span>??

查询第一页和第二页如下图:


  相关解决方案