본문 바로가기

leetcode15

[leetcode / MySQL] 262. Trips and Users 문제 💡 The cancellation rate is computed by dividing the number of canceled (by client or driver) requests with unbanned users by the total number of requests with unbanned users on that day. Write a solution to find the cancellation rate of requests with unbanned users (both client and driver must not be banned) each day between "2013-10-01" and "2013-10-03". Round Cancellation Rate to two decima.. 2024. 1. 31.
[leetcode / MySQL] 570. Managers with at Least 5 Direct Reports 문제 💡 Write a solution to find managers with at least five direct reports. Return the result table in any order. 테이블 형태 풀이 SELECT e2.name FROM Employee e1 INNER JOIN Employee e2 ON e1.managerId=e2.id GROUP BY e1.managerId HAVING COUNT(DISTINCT e1.id) >= 5 해설 SELECT e2.name FROM Employee e1 INNER JOIN Employee e2 ON e1.managerId=e2.id GROUP BY e1.managerId HAVING COUNT(DISTINCT e1.id) >= 5 최소 5명 이.. 2024. 1. 31.
[leetcode / MySQL] 1084. Sales Analysis III 문제 💡 Write a solution to report the products that were only sold in the first quarter of 2019. That is, between 2019-01-01 and 2019-03-31 inclusive. Return the result table in any order. 테이블 형태 풀이 SELECT p.product_id , product_name FROM Product as p JOIN Sales as s ON p.product_id=s.product_id GROUP BY s.product_id HAVING MIN(sale_date) >= '2019-01-01' AND MAX(sale_date) = '2019-01-01' AND MAX(s.. 2024. 1. 30.
[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.