# #177 Nth Highest Salary

#### [https://leetcode.com/problems/nth-highest-salary/](https://leetcode.com/problems/nth-highest-salary/)

{% tabs %}
{% tab title="MS SQL Server" %}
```sql
CREATE FUNCTION getNthHighestSalary(@N INT) RETURNS INT AS
BEGIN
    RETURN (
        /* Write your T-SQL query statement below. */
        SELECT 
            CASE 
                WHEN COUNT(*) >= @N THEN MIN(salary)
                ELSE NULL
            END
        FROM (
            SELECT DISTINCT TOP(@N) salary FROM Employee
            ORDER BY salary DESC
        ) A
        
    );
END
```
{% endtab %}
{% endtabs %}
