inblog logo
|
stupefyee
    SQL문제풀기

    [SQL 문제 풀이] Second Highest Salary (두 번째로 높은 급여)

    Stupefyee's avatar
    Stupefyee
    May 30, 2025
    [SQL 문제 풀이] Second Highest Salary (두 번째로 높은 급여)
    Contents
    내가 작성한 쿼리
    Second Highest Salary - LeetCode
    Can you solve this real interview question? Second Highest Salary - Table: Employee +-------------+------+ | Column Name | Type | +-------------+------+ | id | int | | salary | int | +-------------+------+ id is the primary key (column with unique values) for this table. Each row of this table contains information about the salary of an employee.   Write a solution to find the second highest distinct salary from the Employee table. If there is no second highest salary, return null (return None in Pandas). The 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 | +---------------------+
    Second Highest Salary - LeetCode
    https://leetcode.com/problems/second-highest-salary/submissions/1648634303/
    Second Highest Salary - LeetCode
    notion image
    직원 표에서 두 번째로 높은 급여를 찾기 위한 해결책을 작성하세요. 두 번째로 높은 급여가 없으면 null로 반환합니다.
     

    내가 작성한 쿼리

    MySQL, Oracle

    SELECT MAX(Salary) AS SecondHighestSalary FROM Employee WHERE Salary < (Select MAX(Salary) FROM Employee);
    Share article
    Contents
    내가 작성한 쿼리

    stupefyee

    RSS·Powered by Inblog