윈도우함수5 [leetcode / MySQL] 185. Department Top Three Salaries 문제 💡 A company's executives are interested in seeing who earns the most money in each of the company's departments. A high earner in a department is an employee who has a salary in the top three unique salaries for that department. Write a solution to find the employees who are high earners in each of the departments. Return the result table in any order. 테이블 형태 풀이 SELECT Department, Employee, S.. 2024. 2. 1. [leetcode / MySQL] 178. Rank Scores 문제 💡 Write a solution to find the rank of the scores. The ranking should be calculated according to the following rules: The scores should be ranked from the highest to the lowest. If there is a tie between two scores, both should have the same ranking. After a tie, the next ranking number should be the next consecutive integer value. In other words, there should be no holes between ranks. Retur.. 2024. 2. 1. [leetcode / MySQL] 511. Game Play Analysis1 문제 💡 Write a solution to find the first login date for each player. Return the result table in any order. 테이블 형태 풀이 SELECT player_id, first_login FROM ( SELECT ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY event_date) AS row_n , player_id , event_date AS first_login FROM Activity ) activity WHERE row_n=1 해설 FROM ( SELECT ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY event_date) AS row_.. 2024. 2. 1. [leetcode / MySQL] 180. Consecutive Numbers 문제 💡 Find all numbers that appear at least three times consecutively. Return the result table in any order. 테이블 형태 풀이 SELECT DISTINCT num0 AS ConsecutiveNums FROM (SELECT id , num AS num0 , LEAD(num, 1) OVER (ORDER BY id) AS num1 , LEAD(num, 2) OVER (ORDER BY id) AS num2 FROM Logs) logs WHERE num0=num1 AND num1=num2 해설 SELECT DISTINCT num0 AS ConsecutiveNums FROM (SELECT id , num AS num0 , LEAD(.. 2024. 1. 31. [leetcode / MySQL] 184. Department Highest Salary 문제 💡 Write a solution to find employees who have the highest salary in each of the departments. Return the result table in any order. 테이블 형태 풀이 SELECT D.name AS Department , E.name AS Employee , salary AS Salary FROM Employee E INNER JOIN Department D ON E.departmentId = D.id WHERE (departmentId, salary) IN (SELECT departmentId, MAX(salary) FROM Employee GROUP BY departmentId) 해설 FROM Employee E.. 2024. 1. 30. 이전 1 다음