Employee Salary Ranking Analysis
Beginner Mode
Objective
Write a SQL query to find the second highest salary from the employee table.
Table Schema:
employee
| Column | Type | Description |
|---|---|---|
| employee_id | INTEGER | Unique identifier for each employee |
| employee_name | VARCHAR | Name of the employee |
| salary | DECIMAL | Employee's salary |
| department | VARCHAR | Department where the employee works |
| hire_date | DATE | Date when the employee was hired |
Task Requirements:
- Find the second highest salary across all employees
- If there is no second highest salary (e.g., all salaries are the same or only one employee exists), return NULL
- Display the result as
second_highest_salary
Output columns: second_highest_salary
Examples
Example 1:
Output:
Input:
| employee | ||||
|---|---|---|---|---|
| department | employee_id | employee_name | hire_date | salary |
| Engineering | 1 | Alice Johnson | 2022-01-15 | 85000 |
| Engineering | 2 | Bob Smith | 2021-03-20 | 95000 |
| Marketing | 3 | Carol Davis | 2023-02-10 | 75000 |
| Sales | 4 | David Wilson | 2022-06-05 | 90000 |
| second_highest_salary |
|---|
| 90000 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Amazon