语法: row_number () over (排序规则) 计算每一行数据在结果集的行数
select ROW_NUMBER() over (order by FSalary) as 排序 ,* from T_Employe
查询前五条数据, 并显示行号
select top 5 * from
(select ROW_NUMBER() over(order by FSalary)as rownum ,* from T_Employee )as a
row_number ()只能出现在 select , order by子句中, 不能用在where语句中,
比如: 返回第三行和第五行的数据
select ROW_NUMBER() over (order by FSalary ),* from T_Employee
where (ROW_NUMBER()over (order by FSalary ))>=3
and (ROW_NUMBER()over (order by FSalary ))<=5
这样写 , 则会提示:开窗函数只能出现在 SELECT 或 ORDER BY 子句中。
因此: 可以使用子查询,如下
select *from (
select row_number()over(order by FSalary) as rownum ,* from T_Employee
)as a where rownum >=3 and rownum<=5