Skip to content

Commit 7ccbdf9

Browse files
committed
Update 177. Nth Highest Salary.sql
1 parent 53a0188 commit 7ccbdf9

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed
Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,12 @@
1-
/*
2-
* Order By Clause
3-
* ORDER BY order_by_expression
4-
[ COLLATE collation_name ]
5-
[ ASC | DESC ]
6-
[ ,...n ]
7-
[ <offset_fetch> ]
8-
9-
<offset_fetch> ::=
10-
{
11-
OFFSET { integer_constant | offset_row_count_expression } { ROW | ROWS }
12-
[
13-
FETCH { FIRST | NEXT } {integer_constant | fetch_row_count_expression } { ROW | ROWS } ONLY
14-
]
15-
}
16-
*/
17-
18-
Create FUNCTION getNthHighestSalary(@N INT) returns INT as
1+
# Write your MySQL query statement below.
2+
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
193
BEGIN
20-
Return(
21-
Select Salary
22-
From Employee
23-
Gourp By Salary
24-
Order By Salary DESC
25-
Offset @N-1 rows
26-
Fetch First 1 Rows Only
4+
SET N = N-1;
5+
RETURN (
6+
SELECT DISTINCT(salary) from Employee order by salary DESC
7+
LIMIT 1 OFFSET N
8+
279
);
28-
End
10+
END
11+
12+
# pls upvote if you find solution easy to undestand....!! Thanks..!!!

0 commit comments

Comments
 (0)