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 | 31 |
Tags
- L1정규화
- 깃헙협업
- coding
- 온라인협업
- sql
- 교차 엔트로피
- window function
- 코딩공부
- RLIKE
- branch
- 선형 모형
- 버전충돌
- Git
- 클라우드컴퓨팅
- leetcode
- 편향-분산 교환
- HTML
- mysql
- AWS
- conflict
- full request
- github
- CSS
- merge
- PYTHON
- elastic net
- hackerrank
- L2정규화
- early stopping
- programmers
Archives
- Today
- Total
Im between cherry
LeetCode | MySQL | 180. Consecutive Numbers 본문
180. Consecutive Numbers
leetcode.com/problems/consecutive-numbers/
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