Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 교차 엔트로피
- conflict
- L1정규화
- early stopping
- 온라인협업
- RLIKE
- github
- programmers
- 선형 모형
- elastic net
- HTML
- PYTHON
- merge
- 버전충돌
- L2정규화
- leetcode
- 코딩공부
- CSS
- 클라우드컴퓨팅
- window function
- sql
- coding
- 편향-분산 교환
- AWS
- mysql
- Git
- hackerrank
- full request
- 깃헙협업
- branch
Archives
- Today
- Total
Im between cherry
LeetCode | MySQL | 180. Consecutive Numbers 본문
180. Consecutive Numbers

leetcode.com/problems/consecutive-numbers/
Consecutive Numbers - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
SELECT DISTINCT l.Num AS ConsecutiveNums
FROM logs AS l
INNER JOIN logs AS l_next ON l.id+1 = l_next.id
INNER JOIN logs AS l_next2 ON l.id+2 = l_next2.id
-- two times consecutively
WHERE l.Num = l_next.Num AND l_next.Num = l_next2.Num
-- 윈도우함수로 풀기
SELECT DISTINCT l.Num AS ConsecutiveNums
FROM (
SELECT Num
, LEAD(Num, 1) OVER (ORDER BY Id) AS next
, LEAD(Num, 2) OVER (ORDER BY Id) AS afternext
FROM logs
)l
WHERE l.Num = l.next AND l.Num = l.afternext
'데이터분석 > practice_query' 카테고리의 다른 글
LeetCode | MySQL | 185. Department Top Three Salaries (0) | 2020.09.09 |
---|---|
LeetCode | MySQL | 184. Department Highest Salary (0) | 2020.09.08 |
LeetCode | MySQL | 177. Nth Highest Salary (0) | 2020.09.03 |
Programmers | MySQL | DATETIME에서 DATE로 형 변환 (0) | 2020.09.02 |
Programmers | MySQL | 오랜 기간 보호한 동물(2) (0) | 2020.09.02 |
Comments