Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 59fd086

Browse files
Update 47-00176-second-highest-salary.sql
1 parent cb0c03d commit 59fd086

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

‎47-00176-second-highest-salary.sql‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,36 @@
11

2+
-- create a temp table to get max salary
3+
-- pick the max salary from Employee table which is not in temp table
4+
5+
select max(salary) as SecondHighestSalary
6+
from Employee
7+
where salary not in
8+
(select max(salary)
9+
from Employee)
10+
11+
-----------------------------------------------------------------------------------------------------------
12+
13+
-- write a query to get offset 1 salary(skip first row)
14+
-- but this won't give 'null' as answer
15+
-- so write a simple select, and select that
16+
17+
select(
18+
select distinct salary SecondHighestSalary
19+
from Employee
20+
order by salary desc
21+
limit 1 offset 1
22+
) as SecondHighestSalary
23+
24+
25+
-- amaazon- 2
26+
-- adobe- 2
27+
-- microsoft- 2
28+
-- accencture- 2
29+
-- google- 4
30+
-- oracle- 3
31+
-- tcs- 3
32+
-- infosys- 2
33+
-- yahoo- 2
34+
-- apple- 2
35+
-- mckinsey- 2
36+
-- amdocs- 2

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /