[LeetCode] Consecutive Numbers (self join twice)
# Write your MySQL query statement below SELECT DISTINCT l1.Num as ConsecutiveNums FROM Logs l1 JOIN Logs l2 ON l1.Id = l2.Id - 1 JOIN Logs l3 ON l2.Id = l3.Id - 1 WHERE l1.Num = l2.Num AND l2.Num = l3.Num ; self join 을 2번한다. 총 3개의 table이 join한다 결과 {"headers": ["Id", "Num", "Id", "Num", "Id", "Num"], "values": [[1, 1, 2, 1, 3, 1], [2, 1, 3, 1, 4, 2], [3, 1, 4, 2, 5, 1], [4, 2, 5, 1, 6, 2], [5, 1..
2021. 4. 10.
[LeetCode] Rising Temperature (interval, self join)
데이터 타입이 date라는 점을 주목하자 Select w1.id from weather w1 join weather w2 on w1.recorddate = date_add(w2.recorddate, interval +1 day) where w1.temperature > w2.temperature date_add() Add n days to a date and return the date select *로 출력해보면 {"headers": ["Id", "RecordDate", "Temperature", "Id", "RecordDate", "Temperature"], "values": [[2, "2015-01-02", 25, 1, "2015-01-01", 10], [3, "2015-01-03", 20, 2, ..
2021. 4. 9.