Problem
Example
Thinking
์ต๋๊ฐ์ ๊ฐ์ ธ์ค๋ ๊ฒ์ด ์๋, 2๋ฒ์งธ๋ก ํฐ ๊ฐ์ ๊ฐ์ ธ์ค๋ ๊ฑฐ์์ ๋ฉ์นซ ๊ณ ๋ฏผํ๊ฒ ๋์๋ค.
ํ .. ์ต๋๊ฐ์ ๊ฐ์ ธ์ค๋ ค๋ฉด ๋จ์ํ MAX๋ก ๊ฐ์ ธ์ค๋ฉด ๋์ง๋ง 2๋ฒ์งธ ํฐ ๊ฐ์ ๊ฐ์ ธ์ค๋ ๋ฐฉ๋ฒ์ ๋ฌด์์ผ๊น?
๊ตฌ๊ธ๋ง์ ํ๋ ๋ฐ๋ก ๋ด์ฅ๋ ํจ์๊ฐ ์๋ ๊ฒ ๊ฐ์๋ค.
๊ทธ๋ผ ์ ์ผ ํฐ ๊ฐ๋ณด๋ค ์์ ๊ฐ๋ค ์ค์์ ์ ์ผ ํฐ ๊ฐ์ ๊ฐ์ ธ์ค๋ฉด ๋๊ฒ ๋ค!
Solve
์ ์ถ ๋ต์
SELECT MAX(salary) AS SecondHighestSalary FROM Employee
WHERE salary < (SELECT MAX(salary) FROM Employee);
https://leetcode.com/problems/second-highest-salary
Second Highest Salary - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
'๐ป leetcode > database' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[LeetCode] Database | 178. Rank Scores (0) | 2022.03.16 |
---|---|
[LeetCode] Database | 177. Nth Highest Salary (0) | 2022.01.18 |
[LeetCode] Database | 1179. Reformat Department Table (1) | 2022.01.13 |
[LeetCode] Database | 620. Not Boring Movies (0) | 2022.01.13 |
[LeetCode] Database | 596. Classes More Than 5 Students (0) | 2022.01.12 |