180-Consecutive-Numbers
0x0 题目详情
0x1 解题思路
0x2 代码实现
select distinct Num as ConsecutiveNums
from(
select Num,
case
when @preValue=Num then @count:=@count+1
when (@preValue:=Num) is not null then @count:=1
end as `count`
from `Logs`,(select @count:=null,@preValue:=null) as init
) as countTable
#先执行where,再distinct
where `count`>2;0x3 课后总结
Last updated