융무의 기술블로그
article thumbnail
[SQL][Leetcode] 184. Department Highest Salary
Algorithm/SQL 2020. 6. 21. 23:10

https://leetcode.com/problems/department-highest-salary/ Department 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 Problem Analysis 1. Employee의 DepartmentId 와 Department의 Id가 같은 곳을 JOIN한다. 2. 그중에 MAX함수를 사용하여 Salary가 높은 곳을 찾는다. Solution SELECT D.NAME AS Department..

article thumbnail
[SQL][Leetcode] 183. Customers Who Never Order
Algorithm/SQL 2020. 6. 21. 21:08

https://leetcode.com/problems/customers-who-never-order/ Customers Who Never Order - 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 Problem Analysis 1. Orders table을 LEFT JOIN 시킨다 2. 여기서 참조키가 아닌 것들으 NULL로 나오기 때문에 NULL인 부분을 찾는다 Solution SELECT C.Name AS Customers FROM Customers AS ..

article thumbnail
[SQL][Leetcode] 182. Duplicate Emails
Algorithm/SQL 2020. 6. 21. 19:20

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 Problem Analysis 1. 중복된 이메일 주소를 찾기위해서 먼저 Email 주소를 GROUP BY 해준다. 2.HAVING을 이용하여 개수가 1개 초과인것을 찾는다. Solution SELECT Email FROM Person GROUP BY Email HAVING COUNT(*) >1;

article thumbnail
[SQL][Leetcode] 181. Employees Earning More Than Their Managers
Algorithm/SQL 2020. 6. 21. 19:13

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 Problem Analysis 1. Id와 ManagerId가 같은걸 JOIN 한다. 2.Salary가 managers 보다 사람을 찾는다. Solution SELECT E.Name AS Employee F..

article thumbnail
[SQL][Leetcode] 177. Nth Highest Salary
Algorithm/SQL 2020. 6. 19. 22:43

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 Problem Analysis 1. 먼저 N번째 높은 salary리를 찾는것이기 때문에 ORDERY BY를 이용해서 DESC 한다 2. OFFSET은 몇번째 ROW부터 출력할 것인지 묻는 함수이다 파이썬의 순서에 0,1,2를 생각하면 편할거같다. Solution CREATE FUNCTION ..

article thumbnail
[SQL][Leetcode] 176. Second Highest Salary
Algorithm/SQL 2020. 6. 19. 22:27

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 Problem Analysis 1. 2번째로 높은 salary를 구해야 하기 때문에 where절에 서브쿼리를 이용해서 구했다. Solution SELECT MAX(Salary) AS SecondHighestSalary FROM Employee WHERE Salary < (SELEC..

article thumbnail
[SQL][Leetcode] 175. Combine Two Tables
Algorithm/SQL 2020. 6. 19. 20:31

https://leetcode.com/problems/combine-two-tables/ Combine Two Tables - 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 Problem Analysis 1. provides the following information for each person이므로 각각의 정보에 대해 SELECT 하고 LEFT JOIN을 한다. Solution SELECT P.FirstName, P.LastName, A.City, A.St..