ROW_NUMBER()用法

来源:互联网 发布:怎样打开Windows目录 编辑:程序博客网 时间:2024/06/05 14:27
说明:返回结果集分区内行的序列号,每个分区的第一行从 1 开始。

用例:ROW_NUMBER() OVER(ORDER BY CreateTime DESC)

      select * from (select ROW_NUMBER() Over(order by createtime desc) as rowId,t.* from Table1 t where t.id>10) as  t where rowId between 3 and 5

上面的sql语句返回 Table1表 中 id 大于 10 的所有记录按创建时间倒序的第 3 到第 5 条记录

其中 (select ROW_NUMBER() Over(order by createtime desc) as rowId,t.* from Table1 t where t.id>10) 为数据集Table1表 中 id 大于 10 的所有记录





原创粉丝点击