SQL Row_Number() function in Where Clause

后端 未结 10 1501
野性不改
野性不改 2020-12-02 16:11

I found one question answered with the Row_Number() function in the where clause. When I tried one query, I was getting the following error:

10条回答
  •  無奈伤痛
    2020-12-02 16:59

    To get around this issue, wrap your select statement in a CTE, and then you can query against the CTE and use the windowed function's results in the where clause.

    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
    

提交回复
热议问题