Leetcode(4)
-
[LeetCode] 3482. Analyze Organization Hierarchy
🔗 문제 링크https://leetcode.com/problems/analyze-organization-hierarchy/description/ 🔓 문제 풀이WITH RECURSIVE orgChart AS ( -- 재귀 쿼리 초기문(manager_id가 없는 값=ceo) SELECT employee_id, employee_name, manager_id, salary, department, 1 AS level, CAST(employee_id AS CHAR) AS org_order FROM Employees WHERE manager_id IS NULL UNION ALL ..
2025.03.14 -
[LeetCode] 601. Human Traffic of Stadium
🔗 문제 링크https://leetcode.com/problems/human-traffic-of-stadium/description/ 🔓 문제 풀이풀이1>WITH get_previous AS ( SELECT id, visit_date, people, LAG(id) OVER (ORDER BY id) AS previous_id FROM Stadium WHERE people >= 100),get_diff_id AS ( SELECT id, visit_date, people, previous_id, IF(id - previous_id = 1, 0, 1) AS dif..
2025.03.12 -
[LeetCode] 262. Trips and Users
🔗 문제 링크https://leetcode.com/problems/trips-and-users/description/ 🔓 문제 풀이풀이1>SELECT t.request_at AS 'Day', ROUND( SUM( CASE WHEN t.status IN ('cancelled_by_driver', 'cancelled_by_client') AND u1.banned = 'No' AND u2.banned = 'No' THEN 1 ELSE 0 END ) / NU..
2025.03.11 -
[LeetCode] 185. Department Top Three Salaries
🔗 문제 링크https://leetcode.com/problems/department-top-three-salaries/description/?envType=study-plan-v2&envId=top-sql-50 🔓 문제 풀이WITH tb AS ( SELECT d.name AS Department, e.name AS Employee, e.id, DENSE_RANK() OVER (PARTITION BY e.departmentId ORDER BY e.Salary DESC) AS rank_salary FROM Employee e JOIN Department d ON e.departmentId = d.id)SEL..
2025.03.10