Skip to content

Commit 1036326

Browse files
authored
nth-highest-salary.sql
1 parent aebc511 commit 1036326

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

MySQL/nth-highest-salary.sql

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@
33

44
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
55
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)
6+
SET N = N-1;
7+
RETURN (SELECT DISTINCT(salary) FROM Employee ORDER BY salary DESC
8+
LIMIT 1 Offset N
149
);
1510
END
1611

0 commit comments

Comments
 (0)