Skip to content

Latest commit

 

History

History
20 lines (19 loc) · 683 Bytes

180. Consecutive Numbers.md

File metadata and controls

20 lines (19 loc) · 683 Bytes

180. Consecutive Numbers

Question Link - EN

题目链接 - 中文

Solution v1: silly one

# Write your MySQL query statement below
select distinct i1.num ConsecutiveNums
from Logs i1, Logs i2, Logs i3
where i1.id=i2.id+1 and i2.id=i3.id+1 and i1.num=i2.num and i2.num=i3.num

--IMPORTANT-- Solution v2: right one

连续登录问题

select distinct t.num as ConsecutiveNums from
(select id, num, id - cast(row_number() over(partition by num order by id) as signed) as Number from Logs)
as t
group by t.num, t.Number
having count(t.Number) >= 3