Skip first row in SQL Server 2005?

后端 未结 4 1691
野趣味
野趣味 2021-01-12 13:49

We can select Top 10 or Select Top \'N\' row from SQL Server.

But is there any way to skip first row from the result of top??

I mea

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-12 14:34

    Something like this:

    -- Test table
    declare @T table(ID int)
    
    -- Add test data
    insert into @T 
    select 1 union all
    select 2 union all
    select 3 union all
    select 4 union all
    select 5 union all
    select 6
    
    -- Query using row_number() over(...)
    -- to get rows 2 - 5
    select T.ID
    from (
            select *,
                   row_number() over(order by ID) as rn
            from @T       
         ) as T
    where T.rn between 2 and 5
    

提交回复
热议问题