Write a SQL query to find all numbers that appear at least three times consecutively.

+----+-----+
| Id | Num |
+----+-----+
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 2 |
| 5 | 1 |
| 6 | 2 |
| 7 | 2 |
+----+-----+
For example, given the above Logs table, 1 is the only number that appears consecutively for at least three times. +-----------------+
| ConsecutiveNums |
+-----------------+
| 1 |
+-----------------+

  其实这道题的解法与我在这篇文章中有异曲同工之处:https://www.cnblogs.com/lsyb-python/p/11083828.html,这道题让我们找Num列中连续出现相同数字三次的数字,那么由于需要找三次相同数字,所以我们需要建立三个表的实例,我们可以有a、b和c内交,a和b的id下一个位置比,a和c的下两个位置比,然后将num都相同的数字返回即可:

SELECT a.Num FROM logs as a
JOIN logs as b ON a.Id = b.Id -1
JOIN logs as c on a.Id = c.Id -2
WHERE a.Num = b.Num AND b.Num = c.Num;

  

[LeetCode#180]Consecutive Numbers的更多相关文章

  1. LeetCode Database: Consecutive Numbers

    Consecutive Numbers Write a SQL query to find all numbers that appear at least three times consecuti ...

  2. [LeetCode] 829. Consecutive Numbers Sum 连续数字之和

    Given a positive integer N, how many ways can we write it as a sum of consecutive positive integers? ...

  3. 【SQL】180. Consecutive Numbers

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

  4. 180. Consecutive Numbers

    问题描述 解决方案 select distinct l1.Num as ConsecutiveNums from Logs l1,Logs l2,Logs l3 where l1.Id+1=l2.Id ...

  5. [LeetCode] Consecutive Numbers 连续的数字 --数据库知识(mysql)

    1. 题目名称   Consecutive Numbers 2 .题目地址 https://leetcode.com/problems/consecutive-numbers/ 3. 题目内容 写一个 ...

  6. leetcode Database3(Nth Highest Salary<—>Consecutive Numbers<—>Department Highest Salary)

    一.Nth Highest Salary Write a SQL query to get the nth highest salary from the Employee table. +----+ ...

  7. 【leetcode】1296. Divide Array in Sets of K Consecutive Numbers

    题目如下: Given an array of integers nums and a positive integer k, find whether it's possible to divide ...

  8. [LeetCode] All questions numbers conclusion 所有题目题号

    Note: 后面数字n表明刷的第n + 1遍, 如果题目有**, 表明有待总结 Conclusion questions: [LeetCode] questions conclustion_BFS, ...

  9. LeetCode——Longest Consecutive Sequence

    LeetCode--Longest Consecutive Sequence Question Given an unsorted array of integers, find the length ...

随机推荐

  1. 持续集成(CI):API自动化+Jenkins定时构建

    一.系统管理 1.管理监控配置 系统管理>>系统设置>>管理监控配置 2.设置接收测试报告的邮箱 系统管理>>系统设置>>配置Extended E-ma ...

  2. MongoDB自学------(5)MongoDB分片

    分片 在Mongodb里面存在另一种集群,就是分片技术,可以满足MongoDB数据量大量增长的需求. 当MongoDB存储海量的数据时,一台机器可能不足以存储数据,也可能不足以提供可接受的读写吞吐量. ...

  3. Springmvc配置定时任务注解开发

    1.添加命名空间和xsd约束 xmlns:task="http://www.springframework.org/schema/task" http://www.springfr ...

  4. Zabbix 系列文章

    Zabbix 所有文章目录 本系列文章都基于 Zabbix 4.0 , Zabbix 4.0 是属于长期支持版本,其它的长期支持版本有 3.0 .2.2 . 官方已经有中文文档, 官方文档链接: Za ...

  5. WPF的DataGrid的某个列绑定数据的三种方法(Binding、Converter、DataTrigger)

    最近在使用WPF的时候,遇到某个列的值需要根据内容不同进行转换显示的需求.尝试了一下,大概有三种方式可以实现: 1.传统的Binding方法,后台构造好数据,绑定就行. 2.转换器方法(Convert ...

  6. 网站的favicon图标

    网站的favicon图标 favicon.ico一般用于作为缩略的网站标志,它显示在浏览器的地址栏或者标签上. 制作favicon图标 把图片转换为png图片 把png图片转换为ico图标,这需要借助 ...

  7. emacs c/c++ 中使用的命令大杂烩

    emacs c/c++ 中使用的命令大杂烩 注释,缩进,光标移动等 键盘操作 键盘操作对应函数名 说明 ESC Ctrl \ indent-region 对光标和标记之间的每行文本进行缩进 ESC ; ...

  8. [Go] gocron源码阅读-go语言的结构体

    结构体类型 type 名字 struct{},下面这段是github.com/urfave/cli包里的代码,声明了一个App的结构体类型 type App struct { // The name ...

  9. Windows远程桌面多用户登录的问题

    RDP WRAPPER 同时登录 多用户补丁   https://cloud.tencent.com/developer/article/1460728   解决系统更新导致无法多用户登录的问题 问题 ...

  10. fiddler---Fiddler工具栏功能介绍

    前几篇简单的介绍了Fiddler的功能,对于工具栏的操作只是简单了解,今天写一篇工具栏功能介绍和操作. 工具栏功能介绍 工具栏内容 工具栏依次是:会话保存,数据重放(Replay),转到(GO),数据 ...