Need help with SQL Server query

I want to write this query in SQL Server

from (
    select DISTINCT salary 
    from employee 
    order by salary desc
) 
where rownum = 3;
+3
source share
2 answers

See ROW_NUMBER () :

For instance,

WITH EmployeeSalary AS
(
    select salary, 
        ROW_NUMBER() OVER (order by salary desc) AS 'RowNumber'
    FROM employee 
    group by salary --you can't use DISTINCT because ROW_NUMBER() makes each row distinct
) 
SELECT * 
FROM EmployeeSalary 
WHERE RowNumber = 3;
+7
source
SELECT DISTINCT salary 
FROM employee 
WHERE rownum = 3 
ORDER BY salary 

Covers are optional. Is rownum a column in an employee, or are you only looking for a third row?

0
source

All Articles