Sqlserver中Row_Number的使用场景:分页分组
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
一、 例子集合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] 四、 分组里的最后一条数据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 编辑过 |
关键字查询
相关文章
正在查询... |