Equivalent of LIMIT and OFFSET for SQL Server?

前端 未结 16 2135
天命终不由人
天命终不由人 2020-11-22 06:07

In PostgreSQL there is the Limit and Offset keywords which will allow very easy pagination of result sets.

What is the equivalent syntax f

16条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 06:55

    You can use ROW_NUMBER in a Common Table Expression to achieve this.

    ;WITH My_CTE AS
    (
         SELECT
              col1,
              col2,
              ROW_NUMBER() OVER(ORDER BY col1) AS row_number
         FROM
              My_Table
         WHERE
              <<>>
    )
    SELECT
         col1,
         col2
    FROM
         My_CTE
    WHERE
         row_number BETWEEN @start_row AND @end_row
    

提交回复
热议问题