본문 바로가기

리트코드3

[leetcode / MySQL] 181. Employees Earning More Than Their Managers 문제 💡 Write a solution to find the employees who earn more than their managers. Return the result table in any order. 테이블 형태 풀이 SELECT E1.name AS Employee FROM Employee AS E1 JOIN Employee AS E2 ON E1.managerId=E2.id WHERE E1.salary > E2.salary 해설 SELECT E1.name AS Employee FROM Employee AS E1 JOIN Employee AS E2 ON E1.managerId=E2.id WHERE E1.salary > E2.salary 상사보다 높은 급여를 받은 직원을 출력하는 문제다. manag.. 2024. 1. 29.
[leetcode / MySQL] 183. Customers Who Never Order 문제 💡 Write a solution to find all customers who never order anything. Return the result table in any order. 테이블 형태 풀이 SELECT name AS Customers FROM Customers AS C LEFT JOIN Orders AS O ON C.id = O.customerId WHERE O.id IS NULL ORDER BY C.id 해설 SELECT name AS Customers FROM Customers AS C LEFT JOIN Orders AS O ON C.id = O.customerId WHERE O.id IS NULL ORDER BY C.id Orders(O) 테이블에는 주문한 고객들의 custom.. 2024. 1. 29.
[leetcode / MySQL] 1179. Reformat Department Table 문제 💡 Reformat the table such that there is a department id column and a revenue column for each month. Return the result table in any order. 테이블 형태 풀이 SELECT id , SUM(CASE WHEN month='Jan' THEN revenue END) AS Jan_Revenue , SUM(CASE WHEN month='Feb' THEN revenue END) AS Feb_Revenue , SUM(CASE WHEN month='Mar' THEN revenue END) AS Mar_Revenue , SUM(CASE WHEN month='Apr' THEN revenue END) AS Apr_R.. 2024. 1. 29.