My accepted solution
My first solution was with CTE query, but it gave me error - I guess it\'s not supported on LeetCode.\nSo, I modified it to subquery and that gave me 1807 ms si
My first solution was with CTE query, but it gave me error - I guess it\'s not supported on LeetCode.\nSo, I modified it to subquery and that gave me 1807 ms since I used GROUP BY. After adding additional subquery I was able to speed up it to 686ms and that was faster than ~79%.\n\nHere is the solution:\n\n```\nCREATE FUNCTION getNthHighestSalary(@N INT) RETURNS INT AS\nBEGIN\n    RETURN (\n        /* Write your T-SQL query statement below. */\n        SELECT Salary FROM \n        (\n            SELECT\n                row_number() OVER (ORDER BY salary DESC) AS row_num,            \n                emp.salary\n            FROM (SELECT DISTINCT Salary FROM Employee) emp\n        ) result\n        WHERE row_num = @N        \n    );\nEND\n```
['MySQL', 'MS SQL Server']