Is there any direct way of using row_number() function? I want to find 2 nd highest salary
SELECT DISTINCT id
    ,salary
    ,depid
    ,ROW_NUMBER() OVER (
        PARTITION BY depid ORDER BY salary DESC
        ) AS rownum
FROM emp
WHERE rownum = 2;
It gives an error, However the below code works fine.
SELECT *
FROM (
    SELECT DISTINCT id
        ,salary
        ,depid
        ,ROW_NUMBER() OVER (
            PARTITION BY depid ORDER BY salary DESC
            ) AS rownum
    FROM emp
    ) AS t
WHERE t.rownum = 2;
Is any way of directly using the row_number() function as in the first option which is giving the error?
 
     
     
     
     
     
    