SqlServer 分頁 ROW_NUMBER() OVER(Order by * DESC ) AS RowNumber
語法如下:
select * from (
select *, ROW_NUMBER() OVER(Order by a.CreateTime DESC ) AS RowNumber from table_name as a) as b
where RowNumber BETWEEN 1 and 5
例項如下
select * from
(
select ROW_NUMBER()over(order by DWHYBH ) as rowNo,* from C60DWYHXX
) as t
where rowNo between 4 and 8
and t.DWJC like '%%'
and t.DWQC like '%%'
所用資料表為:
CREATE TABLE [dbo].[C60DWYHXX](
[DWHYBH] [varchar](20) NOT NULL primary key ,
[DWJC] [varchar](20) NOT NULL,
[DWQC] [varchar](60) NOT NULL,
[DWLB] [int] NOT NULL,
[FRDB] [dbo].[xm] NULL,
[FRDBZSH] [varchar](30) NULL,
[LXR] [dbo].[xm] NULL,
[LXRMOBILE] [dbo].[mobile] NULL,
[QYEMAIL] [varchar](50) NULL,
[DWLANDLINE] [varchar](15) NULL,
[QYWZDZ] [varchar](40) NULL,
[YHMM] [char](32) NULL,
[DJRQ] [date] NULL,
[UniqueID] [int] NOT NULL,
[wTag] [int] NULL,
[StrTag] [varchar](255) NULL,
[RecVersion] [bigint] NULL,
[YHID] [uniqueidentifier] NULL
)
第二部分:自己寫的拼接有省市縣三級拼接的SQL語句
SELECT ROW_NUMBER()OVER ( order by HYBH) AS rowNo ,b.XM
,(
select xzqhwm from Z21XZQH e where e.XZQH in (select SUBSTRING(f.xzqh,0,3)+'0000' from C02YHJBXX f
left join Z21XZQH d on f.XZQH=d.XZQH
where f.XZQH=d.XZQH and f.YHID=a.YHID )) as fir
,(
select xzqhwm from Z21XZQH e where e.XZQH in (select SUBSTRING(f.xzqh,0,5)+'00' from C02YHJBXX f
left join Z21XZQH d on f.XZQH=d.XZQH
where f.XZQH=d.XZQH and f.YHID=a.YHID )) as sec
,(
select XZQHWM
from C02YHJBXX c
left join Z21XZQH d on c.XZQH=d.XZQH
where c.XZQH=d.XZQH and c.YHID=a.YHID
) as thir
,b.XZQH,a.HYBH,a.YHID,a.UniqueID
from C70HYGR a left join C02YHJBXX b on a.YHID=b.YHID
where 1=1
--select SUBSTRING(XZQH,0,3)+'0000' from C02YHJBXX
--select xzqh from C02YHJBXX
查詢結果如下圖所示
子查詢裡巢狀了in關鍵字。嘻嘻。效率應該不高。但是省的寫程式碼拼接datatable了
相關文章
- 理解了row_number()over (partition by order by )的方法
- row_number() OVER (PARTITION BY COL1 ORDER BY COL2)
- ROWNUMBER() OVER( PARTITION BY COL1
- SQL-ROWNUMBER-OVER彙總SQL
- MySQL 5.7:desc order by反向定位MySql
- row_number() over函式函式
- row_number() over,rank() over,dense_rank() over的區別
- row_number() partition order by 的使用
- sql中row_number over語句SQL
- SQL語句中的rank () over , row_number() over ,rank_dense ()SQL
- Oracle分頁查詢之order byOracle
- ROW_NUMBER() OVER() 分析函式的用法函式
- ROW_NUMBER() OVER函式的基本用法函式
- MYSQL-實現ORACLE- row_number() over(partition by ) 分組排序功能.MySqlOracle排序
- 使用row_number()分頁函式取代group by函式
- SQL Server的分頁優化及Row_Number()分頁存在的問題SQLServer優化
- lead lag rank()over()dense_rank()row_number()over()rollupcube幾大分析函式函式
- oracle下資料的排序分組row_number() over()--分析函式,可用於去重Oracle排序函式
- Oracle 中的 ROW_NUMBER() OVER() 分析函式的用法Oracle函式
- SqlServer-儲存過程分頁SQLServer儲存過程
- Sql Server 2005 row_number()分頁效能測試SQLServer
- SQLServer使用case when中的order bySQLServer
- MySQL order by limit 分頁資料重複問題MySqlMIT
- MYSQL SQLServer分頁查詢的實現MySqlServer
- sqlserver2005資料庫映象 的switch over 和fail overSQLServer資料庫AI
- 拋棄以往分頁方式,改用ROW_NUMBER()加BETWEEN方式的分頁儲存過程,特此分享儲存過程
- sqlserver儲存過程實現多表分頁SQLServer儲存過程
- SQLServer2005新的高效分頁方法SQLServer
- SQLServer 2005通用分頁儲存過程SQLServer儲存過程
- order by改分組排序排序
- 【清清月兒】用SQL 2005的ROW_NUMBER() 實現分頁功能SQL
- 巧用row_number() over()函式,選取重複記錄中想要的值函式
- Hibernate5.1+Sqlserver2000分頁查詢SQLServer
- MySql、SqlServer、Oracle 三種資料庫查詢分頁方式MySqlServerOracle資料庫
- 使用Hibernate連線Sqlserver可以用分頁功能嗎?SQLServer
- 盤點現在用的SqlServer 5種分頁方式和拉姆達表示式分頁,進來看看吧。SQLServer
- sqlserver使用order by case when進行優先順序排序SQLServer排序
- Mysql系列第八講 詳解排序和分頁(order by & limit)及存在的坑MySql排序MIT