We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent aebc511 commit 1036326Copy full SHA for 1036326
MySQL/nth-highest-salary.sql
@@ -3,14 +3,9 @@
3
4
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
5
BEGIN
6
- RETURN (
7
- # Write your MySQL query statement below.
8
- SELECT MAX(Salary) /*This is the outer query part */
9
- FROM Employee Emp1
10
- WHERE (N-1) = ( /* Subquery starts here */
11
- SELECT COUNT(DISTINCT(Emp2.Salary))
12
- FROM Employee Emp2
13
- WHERE Emp2.Salary > Emp1.Salary)
+SET N = N-1;
+ RETURN (SELECT DISTINCT(salary) FROM Employee ORDER BY salary DESC
+ LIMIT 1 Offset N
14
);
15
END
16
0 commit comments