Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Table: Employee
+-------------+------+
| Column Name | Type |
+-------------+------+
| id | int |
| salary | int |
+-------------+------+
id is the primary key column for this table.
Each row of this table contains information about the salary of an employee.
Write an SQL query to report the second highest salary from the Employee
table. If there is no second highest salary, the query should report null
.
The query result format is in the following example.
Example 1:
Input:
Employee table:
+----+--------+
| id | salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
Output:
+---------------------+
| SecondHighestSalary |
+---------------------+
| 200 |
+---------------------+
Example 2:
Input:
Employee table:
+----+--------+
| id | salary |
+----+--------+
| 1 | 100 |
+----+--------+
Output:
+---------------------+
| SecondHighestSalary |
+---------------------+
| null |
+---------------------+
select max(Salary) as SecondHighestSalary from Employee
where Salary < (select max(Salary) from Employee)
select max(Salary) as SecondHighestSalary from Employee where Salary < (select max(Salary) from Employee);
SELECT IFF(COUNT(id) >= 1, MAX(salary), null) as SecondHighestSalary from Employee
WHERE salary < (SELECT MAX(salary) from Employee)
In our experience, we suggest you solve this Second Highest Salary LeetCode Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the Second Highest Salary LeetCode Solution
I hope this Second Highest Salary LeetCode Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions >>