zoukankan      html  css  js  c++  java
  • MYSQL-连续出现的数字

    编写一个 SQL 查询,查找所有至少连续出现三次的数字。

    +----+-----+
    | Id | Num |
    +----+-----+
    | 1 | 1 |
    | 2 | 1 |
    | 3 | 1 |
    | 4 | 2 |
    | 5 | 1 |
    | 6 | 2 |
    | 7 | 2 |
    +----+-----+
    例如,给定上面的 Logs 表, 1 是唯一连续出现至少三次的数字。

    +-----------------+
    | ConsecutiveNums |
    +-----------------+
    | 1 |
    +-----------------+

    来源:力扣(LeetCode)

    select distinct a.Num as ConsecutiveNums  from Logs a join Logs b on b.Id = a.Id+1 join Logs c on c.Id = a.Id+2 where a.Num = b.Num and b.Num=c.Num
     
  • 相关阅读:
    leetcode 414
    Leetcode 495
    Leetcode 485题
    Python 24点(2)
    python 24点
    我的第一次作业
    Django
    multiprocessing模块
    遍历文档树
    shutil模块
  • 原文地址:https://www.cnblogs.com/corvus/p/12026085.html
Copyright © 2011-2022 走看看