How to select a row based on its row number?

前端 未结 6 1470
猫巷女王i
猫巷女王i 2020-12-28 18:12

I\'m working on a small project in which I\'ll need to select a record from a temporary table based on the actual row number of the record.

How can I select a record

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-28 18:33

    What you're looking for is the row_number() function, as Kaf mentioned in the comments.

    Here is an example:

    WITH MyCte AS 
    (
        SELECT   employee_id,
                 RowNum = row_number() OVER ( order by employee_id )
        FROM     V_EMPLOYEE 
        ORDER BY Employee_ID
    )
    SELECT  employee_id
    FROM    MyCte
    WHERE   RowNum > 0
    

提交回复
热议问题