Row Offset in SQL Server

后端 未结 16 2411
醉酒成梦
醉酒成梦 2020-11-22 05:53

Is there any way in SQL Server to get the results starting at a given offset? For example, in another type of SQL database, it\'s possible to do:

SELECT * FR         


        
16条回答
  •  旧时难觅i
    2020-11-22 06:31

    In SqlServer2005 you can do the following:

    DECLARE @Limit INT
    DECLARE @Offset INT
    SET @Offset = 120000
    SET @Limit = 10
    
    SELECT 
        * 
    FROM
    (
       SELECT 
           row_number() 
       OVER 
          (ORDER BY column) AS rownum, column2, column3, .... columnX
       FROM   
         table
    ) AS A
    WHERE 
     A.rownum BETWEEN (@Offset) AND (@Offset + @Limit-1) 
    

提交回复
热议问题