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. ABP开发框架前后端开发系列---(6)ABP基础接口处理和省份城市行政区管理模块的开发

    最近没有更新ABP框架的相关文章,一直在研究和封装相关的接口,总算告一段落,开始继续整理下开发心得.上次我在随笔<ABP开发框架前后端开发系列---(5)Web API调用类在Winform项目 ...

  2. Spring Security 教程 大牛的教程

    https://www.iteye.com/blog/elim-2247073 Spring Security 教程 Spring Security(20)——整合Cas Spring Securit ...

  3. django9-ajax

    1.ajax 局部刷新 ,不可能每次提交请求刷新整个页面 2.ajax实例 在不刷新整个的情况下完成计算器 ,ajax的post需要添加csrftoken 1)设置一个组件ajaxcsrf.html ...

  4. CSS3常用新特性

    CSS3的新特性 新增CSS3特性有兼容性问题,ie9+才支持 移动端支持优于PC端 新增选择器和盒子模型以及其他特性 CSS新增选择器 属性选择器 属性选择器可以根据元素特定属性来选择元素,这样就可 ...

  5. 权限管理——ACL权限

    权限管理 ACL权限 用于解决用户对文件身份不足 命令:[root@localhost ~]#dumpe2fs -h /dev/sd3 作用:查询指定分区详细的文件系统给信息 选项 -h:仅显示超级块 ...

  6. Dynamics 365 We API ODATA语法根据父记录查询子记录,根据子记录查询父记录(附上根据团队,队列名称查成员)

    微软动态CRM专家罗勇 ,回复333或者20190508可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me! 先举个N:N关系的例子.这里以根据团队的名称查找其所有团队成员的 ...

  7. Python的 json 、 hashlib 、 Base64 模块

    json模块 简介 全称"JavaScript Object Notation" (JavaScript对象表示法)它是一种基于文本,独立于语言的轻量级数据交换格式 以易于让人阅读 ...

  8. Incorrect datetime value: '' for column 'examDate' at row 1

    出问题的程序:user.setCreateTime(new Date()); 控制台图片一张,问题是:Incorrect datetime value: '' for column 'createTi ...

  9. minimize.m:共轭梯度法更新BP算法权值

    minimize.m:共轭梯度法更新BP算法权值 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ Carl Edward Rasmussen在高斯机器学 ...

  10. nginx配置中root和alias的区别

    例:访问http://127.0.0.1/download/*这个目录时候让他去/opt/app/code这个目录找. 方法一(使用root关键字): location / { root /usr/s ...