[MySQL] 활용
0) Second Highest Salary (problem) Input: Employee table: +----+--------+ | id | salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+--------+ Output: +---------------------+ | SecondHighestSalary | +---------------------+ | 200 | +---------------------+ solution 1 SELECT max(Salary) as SecondHighestSalary FROM Employee WHERE Salary < (SELECT max(Salary) FROM Employee); solution 2 (n-th rank 구할 때 적절할 듯) WITH CTE AS (SELECT Salary, RANK () OVER (ORDER BY Salary desc) AS RANK_desc FROM Employee) SELECT MAX(salary) AS SecondHighestSalary FROM CTE WHERE RANK_desc = 2 with 절 동일한 SQL 문이 반복되어 성능을 높이기 위해 사용됨....