목록SQL 문제풀이/Leetcode (7)
취미가 좋다
https://leetcode.com/problems/consecutive-numbers/ Consecutive Numbers - 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 Solution select distinct l.Num as ConsecutiveNums from Logs l left join Logs r on l.Num = r.Num and r.Id < l.Id and l.Id -r.Id
https://leetcode.com/problems/rank-scores/ Rank Scores - 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 Solution SELECT Score, @rank := @rank + (@pre (@pre := Score)) 'Rank' FROM Scores, (SELECT @rank := 0, @pre := -1) init ORDER BY Score desc 릿코드에서는 SET으로 변수 선언이 왜인지 안된다. FROM에 있는..
https://leetcode.com/problems/duplicate-emails/ Duplicate Emails - 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 Solution SELECT Email FROM Person GROUP BY Email HAVING COUNT(Email) > 1 Email이 같은 항목의 개수를 보고 중복되는 데이터를 반환한다. GROUP BY ... HAVING 을 이용하여 중복되는 데이터를 묶는다. COUNT 를 이용하여 중복..
https://leetcode.com/problems/employees-earning-more-than-their-managers/ Employees Earning More Than Their Managers - 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 Solution SELECT A.Name as Employee FROM Employee A INNER JOIN Employee B ON A.ManagerID = B.ID WHERE A.Salary > B.S..
https://leetcode.com/problems/nth-highest-salary/ Nth 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 Solution CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN DECLARE M INT; SET M=N-1; RETURN ( # Write your MySQL query statement below. SELECT DISTINCT ..
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 Solution SELECT Max(Salary) SecondHighestSalary FROM Employee WHERE Salary < (SELECT Max(Salary) FROM Employee) 서브 쿼리에 미리 제일 큰 수를 구해놓고, 그 다음 큰 수를 찾는다. SELECT..