3 SOLUTIONS ( DENSE_RANK(), ROW_NUMBER, SUB QUERY ) 🥶🥶🥶
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# DENSE_RANK()\n```\nCREATE FUNCTION getNthHighestSalary(@N INT) \nRETURNS INT AS\nBEGIN\n    RETURN(\n            SELECT \n               MAX(salary) \n            FROM\n                (\n                    SELECT\n                        salary,\n                        DENSE_RANK() OVER(ORDER BY salary DESC) RankID\n                    FROM\n                        Employee\n                )tbl\n            WHERE\n                RankID = @N\n    )\nEND\n```\n\n# ROW_NUMBER()\n```\n\nCREATE FUNCTION getNthHighestSalary(@N INT) \nRETURNS INT AS\nBEGIN\n    RETURN(\n            SELECT \n                salary\n            FROM\n                (\n                    SELECT\n                        salary,\n                        ROW_NUMBER() OVER(ORDER BY salary DESC) RankID\n                    FROM\n                        (\n                            SELECT DISTINCT salary FROM Employee\n                        )tbl\n                )tbl2\n            WHERE\n                RankID = @N\n    )\nEND\n\n```\n\n# SUB QUERY\n```\n    CREATE FUNCTION getNthHighestSalary(@N INT) \n    RETURNS INT AS\n    BEGIN      \n                RETURN  (           \n                SELECT\n                    salary\n                FROM\n                    (\n                        SELECT DISTINCT salary FROM Employee \n                    )tbl\n                ORDER BY\n                    salary DESC\n                OFFSET IIF(@N < 0 OR @N = 0, (SELECT COUNT(DISTINCT id) FROM Employee) + 1, @N ) - 1 ROWS \n                FETCH NEXT 1 ROW ONLY\n                        ) \n    END\n```
['MS SQL Server']