Sqlserver中Row_Number的使用場景:分頁分組
當(dāng)前位置:點晴教程→知識管理交流
→『 技術(shù)文檔交流 』
一、 例子集合select ROW_NUMBER() over (order by creatime) as num ,[name] ,[creatime] ,[count] from [TEST].[dbo].[Table_1] 二、 分頁declare @pageNum int declare @pageSize int set @pageNum = 3 set @pageSize = 3 select [name] ,[creatime] ,[count] from(select ROW_NUMBER() over (order by creatime) as num ,[name] ,[creatime] ,[count] from [TEST].[dbo].[Table_1]) as tempT where (@pageNum - 1)* @pageSize < num and num <= @pageNum * @pageSize 三、 分組并排序select ROW_NUMBER() over (PARTITION by name order by creatime) as num ,[name] ,[creatime] ,[count] from [TEST].[dbo].[Table_1] 四、 分組里的最后一條數(shù)據(jù)select [name] ,[creatime] ,[count] from(select ROW_NUMBER() over (PARTITION by name order by creatime desc) as num ,[name] ,[creatime] ,[count] from [TEST].[dbo].[Table_1]) as tempT where num = 1 該文章在 2023/10/28 15:17:18 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |