File tree Expand file tree Collapse file tree 1 file changed +10
-26
lines changed
LeetCode SQL 50 Solution/177. Nth Highest Salary Expand file tree Collapse file tree 1 file changed +10
-26
lines changed Original file line number Diff line number Diff line change 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
193BEGIN
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..!!!
You can’t perform that action at this time.
0 commit comments