File tree Expand file tree Collapse file tree 7 files changed +41
-19
lines changed
0176.Second Highest Salary Expand file tree Collapse file tree 7 files changed +41
-19
lines changed Original file line number Diff line number Diff line change 4646
4747```
4848
49- ### ** ... **
49+ ### ** sql **
5050```
51-
51+ select (select distinct Salary from Employee order by Salary desc limit 1 offset 1) as
52+ SecondHighestSalary;
5253```
5354
54- <!-- tabs:end -->
55+ <!-- tabs:end -->
Original file line number Diff line number Diff line change 6565
6666```
6767
68- ### ** ... **
68+ ### ** sql **
6969```
70-
70+ select (select distinct Salary from Employee order by Salary desc limit 1 offset 1) as
71+ SecondHighestSalary;
7172```
7273
73- <!-- tabs:end -->
74+ <!-- tabs:end -->
Original file line number Diff line number Diff line change 1- select (select distinct Salary from Employee order by Salary desc limit 1 offset 1 ) as
1+ select (select distinct Salary from Employee order by Salary desc limit 1 offset 1 ) as
22SecondHighestSalary;
Original file line number Diff line number Diff line change 4646
4747```
4848
49- ### ** ... **
49+ ### ** sql **
5050```
51-
51+ CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
52+ BEGIN
53+ set N = N-1;
54+ RETURN (
55+ # Write your MySQL query statement below.
56+ SELECT (SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT 1 OFFSET N) AS SecondHighestSalary
57+ );
58+ END
5259```
5360
54- <!-- tabs:end -->
61+ <!-- tabs:end -->
Original file line number Diff line number Diff line change 6565
6666```
6767
68- ### ** ... **
68+ ### ** sql **
6969```
70-
70+ CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
71+ BEGIN
72+ set N = N-1;
73+ RETURN (
74+ # Write your MySQL query statement below.
75+ SELECT (SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT 1 OFFSET N) AS SecondHighestSalary
76+ );
77+ END
7178```
7279
73- <!-- tabs:end -->
80+ <!-- tabs:end -->
Original file line number Diff line number Diff line change 5454
5555```
5656
57- ### ** ... **
57+ ### ** sql **
5858```
59-
59+ select
60+ Score,
61+ (select count(*) from (select distinct Score s from Scores) tmp where s>=Score) Rank
62+ from Scores order by Rank;
6063```
6164
62- <!-- tabs:end -->
65+ <!-- tabs:end -->
Original file line number Diff line number Diff line change 8181
8282```
8383
84- ### ** ... **
84+ ### ** sql **
8585```
86-
86+ select
87+ Score,
88+ (select count(*) from (select distinct Score s from Scores) tmp where s>=Score) Rank
89+ from Scores order by Rank;
8790```
8891
89- <!-- tabs:end -->
92+ <!-- tabs:end -->
You can’t perform that action at this time.
0 commit comments