File tree Expand file tree Collapse file tree 9 files changed +48
-10
lines changed
0176.Second Highest Salary Expand file tree Collapse file tree 9 files changed +48
-10
lines changed Original file line number Diff line number Diff line change 3535### ** SQL**
3636
3737```
38-
38+ select (select distinct Salary from Employee order by Salary desc limit 1 offset 1) as
39+ SecondHighestSalary;
3940```
4041
41- <!-- tabs:end -->
42+ <!-- tabs:end -->
Original file line number Diff line number Diff line change 5656### ** SQL**
5757
5858```
59-
59+ select (select distinct Salary from Employee order by Salary desc limit 1 offset 1) as
60+ SecondHighestSalary;
6061```
6162
62- <!-- tabs:end -->
63+ <!-- 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
2+ SecondHighestSalary;
Original file line number Diff line number Diff line change 3535### ** SQL**
3636
3737```
38-
38+ CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
39+ BEGIN
40+ set N = N-1;
41+ RETURN (
42+ # Write your MySQL query statement below.
43+ SELECT (SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT 1 OFFSET N) AS SecondHighestSalary
44+ );
45+ END
3946```
4047
41- <!-- tabs:end -->
48+ <!-- tabs:end -->
Original file line number Diff line number Diff line change 5656### ** SQL**
5757
5858```
59-
59+ CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
60+ BEGIN
61+ set N = N-1;
62+ RETURN (
63+ # Write your MySQL query statement below.
64+ SELECT (SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT 1 OFFSET N) AS SecondHighestSalary
65+ );
66+ END
6067```
6168
62- <!-- tabs:end -->
69+ <!-- tabs:end -->
Original file line number Diff line number Diff line change 1+ CREATE FUNCTION getNthHighestSalary (N INT ) RETURNS INT
2+ BEGIN
3+ set N = N- 1 ;
4+ RETURN (
5+ # Write your MySQL query statement below.
6+ SELECT (SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT 1 OFFSET N) AS SecondHighestSalary
7+ );
8+ END
Original file line number Diff line number Diff line change 4343### ** SQL**
4444
4545```
46+ select
47+ Score,
48+ (select count(*) from (select distinct Score s from Scores) tmp where s>=Score) Rank
49+ from Scores order by Rank;
4650
4751```
4852
49- <!-- tabs:end -->
53+ <!-- tabs:end -->
Original file line number Diff line number Diff line change 7272### ** SQL**
7373
7474```
75+ select
76+ Score,
77+ (select count(*) from (select distinct Score s from Scores) tmp where s>=Score) Rank
78+ from Scores order by Rank;
7579
7680```
7781
78- <!-- tabs:end -->
82+ <!-- tabs:end -->
Original file line number Diff line number Diff line change 1+ select
2+ Score,
3+ (select count (* ) from (select distinct Score s from Scores) tmp where s>= Score) Rank
4+ from Scores order by Rank;
You can’t perform that action at this time.
0 commit comments