|
1 | 1 |
|
| 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