링크
https://leetcode.com/problems/second-highest-salary/description/
문제
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.
정답
select
(select distinct Salary
from Employee
order by salary desc
limit 1 offset 1
)
as SecondHighestSalary;
SELECT MAX(SALARY) AS SecondHighestSalary
FROM EMPLOYEE
WHERE SALARY <>(SELECT MAX(SALARY) FROM EMPLOYEE);
새롭게 이해한 내용
SELECT * FROM 테이블명 LIMIT 10; -- 처음 부터 10개만 출력하기 (1 ~ 10)
SELECT * FROM 테이블명 LIMIT 100, 10; -- 100번째부터 그 후 10개 출력하기 (101 ~ 110)
SELECT * FROM 테이블명 ORDERS LIMIT 20 OFFSET 5; -- 5번째 행 부터 25행 까지 출력 (6 ~ 25)
SELECT * FROM 테이블명 ORDERS LIMIT 5, 20; -- limit 5, 20 과 같다고 보면 된다.
'[업무 지식] > MySQL' 카테고리의 다른 글
[REGEXP] Find Users With Valid E-Mails (0) | 2024.11.18 |
---|---|
[GROUP_CONCAT] Group Sold Products By The Date (0) | 2024.11.18 |
[delete] Delete Duplicate Emails (0) | 2024.11.14 |
[LIKE] Patients With a Condition (0) | 2024.11.14 |
[upper, lower] Fix Names in a Table (0) | 2024.11.14 |