-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15.sql
More file actions
25 lines (21 loc) · 688 Bytes
/
15.sql
File metadata and controls
25 lines (21 loc) · 688 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- Question 15
-- Write a SQL query to get the second highest salary from the Employee table.
-- +----+--------+
-- | Id | Salary |
-- +----+--------+
-- | 1 | 100 |
-- | 2 | 200 |
-- | 3 | 300 |
-- +----+--------+
-- For example, given the above Employee table, the query should return 200 as the second highest salary.
-- If there is no second highest salary, then the query should return null.
-- +---------------------+
-- | SecondHighestSalary |
-- +---------------------+
-- | 200 |
-- +---------------------+
-- Solution
select max(salary) as SecondHighestSalary
from employee
where salary ! = (Select max(salary)
from employee)