SQL 單表多條記錄分組查詢分頁程式碼

暖楓無敵發表於2012-04-20

SQL表結構如下圖:


SQL 分頁語句:

SELECT TOP 5 *,(select count(*)   inum from   
(select distinct  AreaID,AreaTypeID,lifeYear,[State],RelatedID from MonitorBaseEnterInfo where  1=1) i ) as CountNum  FROM       
  (SELECT ROW_NUMBER() OVER ( order by lifeYear desc) AS RowNumber,* FROM (select distinct  AreaID,AreaTypeID,lifeYear,[State],RelatedID   
    from MonitorBaseEnterInfo where  1=1 ) mm  ) A  
     WHERE RowNumber > 5 *(1-1)  


查詢第一頁和第二頁如下圖:




相關文章