美文网首页
mysql 窗口函数lead()

mysql 窗口函数lead()

作者: 要不再等等 | 来源:发表于2020-08-13 14:51 被阅读0次

    查询出表中连续三个相同的数
    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

    相关文章

      网友评论

          本文标题:mysql 窗口函数lead()

          本文链接:https://www.haomeiwen.com/subject/qzgbdktx.html