Lead2 [leetcode / MySQL] 626. Exchange Seats 문제 💡 Write a solution to swap the seat id of every two consecutive students. If the number of students is odd, the id of the last student is not swapped. Return the result table ordered by id in ascending order. 테이블 형태 풀이 SELECT id , CASE WHEN id=(SELECT COUNT(*) FROM Seat) AND id%2=1 THEN student WHEN id%2=1 THEN LEAD(student, 1) OVER (ORDER BY id) WHEN id%2=0 THEN LAG(student, 1) OVER(ORDER BY.. 2024. 2. 22. [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. 이전 1 다음