Employee Salary Ranking Analysis
Amazon ☯️ Medium SQL
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:

Input:

employee
departmentemployee_idemployee_namehire_datesalary
Engineering1Alice Johnson2022-01-1585000
Engineering2Bob Smith2021-03-2095000
Marketing3Carol Davis2023-02-1075000
Sales4David Wilson2022-06-0590000

Output:
second_highest_salary
90000
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →