查询出表中连续三个相同的数
select distinct num from (
select num,lead(num,1)over()as num1,lead(num,2)over()as num2 from logs
) t where num = num1 and num1 = num2
也可以用排序取值
select distinct Num ConsecutiveNums from(
select Num,
cast(
case
when @pre = Num then @rank:=@rank+1
when @pre:=Num then @rank:=1
end as signed) as rankNo
from Logs,(select @rank:=0,@pre:=-1) init order by Id
) t where rankNo = 3
网友评论