ROWNUM查询返回

时间:2016-03-23 18:32:23

标签: sql sql-server

我习惯了rownum并试图理解逻辑。

例如,如果一个部门'表包含10行以上,我们运行一个查询:

Select * from Department 
where Rownum between 1 and 7

此查询将返回多少行?

1 个答案:

答案 0 :(得分:0)

使用

select top 7 ... 
from Department 
order by some_field

没有rownum在哪里 或者像这样使用ROW_NUMBER():

with
  dep as (select ROW_NUMBER() over (order by some_field) as lp, d.*
  from Department d)
select * from dep where lp between 1 and 7