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
- 클라우드컴퓨팅
- early stopping
- CSS
- full request
- Git
- 코딩공부
- RLIKE
- L2정규화
- elastic net
- 깃헙협업
- branch
- coding
- github
- L1정규화
- HTML
- merge
- 교차 엔트로피
- leetcode
- mysql
- 버전충돌
- PYTHON
- 선형 모형
- 편향-분산 교환
- conflict
- window function
- programmers
- 온라인협업
- hackerrank
- sql
- AWS
Archives
- Today
- Total
Im between cherry
Leet Code | MySQL | 180. Consecutive Numbers 본문
180. Consecutive Numbers
https://leetcode.com/problems/consecutive-numbers/
Write a SQL query to find all numbers that appear at least three times consecutively.
-- 윈도우함수로 풀기
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.nex AND l.Num = l.afternext
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
'데이터분석 > practice_query' 카테고리의 다른 글
Leet Code | MySQL | 185. Department Top Three Salaries (0) | 2020.08.30 |
---|---|
Leet Code | MySQL | 184. Department Highest Salary (0) | 2020.08.30 |
Leet Code | MySQL | 196. Delete Duplicate Emails (0) | 2020.08.30 |
Leet Code | MySQL | 627. Swap Salary (0) | 2020.08.30 |
Leet Code | MySQL | 181. Employees Earning More Than Their Managers (0) | 2020.08.30 |
Comments