Consecutive Numbers
来源:互联网 发布:java开发赛车游戏 编辑:程序博客网 时间:2024/06/15 06:22
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.
题意:将num连接出现超过3次的数找出来
思路:在select语句中添加计数信息,原来select还有这种功能
select distinct Num from ( select Num, case when @prevNum = Num then @count := @count + 1 when (@prevNum := Num) is not null then @count := 1 end n from Logs, (select @prevNum := NULL) r order by Id) a where n >= 3
0 0
- Consecutive Numbers
- Consecutive Numbers
- Consecutive Numbers
- Consecutive Numbers
- LeetCode | Consecutive Numbers
- [leetcode] Consecutive Numbers
- consecutive numbers 180
- LeetCode:Consecutive Numbers
- Leetcode:Consecutive Numbers
- [LeetCode] Consecutive Numbers - SQL
- Leetcode: Consecutive Numbers
- [LeetCode][Database]Consecutive Numbers
- LeetCode OJ Consecutive Numbers
- LeetCode_OJ【180】Consecutive Numbers
- [Leetcode] [Database] Consecutive Numbers
- leetcode 180. Consecutive Numbers
- 【Leetcode】Consecutive Numbers
- leetcode-Consecutive numbers
- Docker 使用方法总结之:容器的基本操作
- Sequoiadb1.10集群性能测试报告
- 头肩底
- OpenCL编程步骤(一):创建上下文
- Mac上的抓包工具Charles
- Consecutive Numbers
- JavaScript常用方法函数汇集
- 讲讲从用户的角度解缆的细准营销之讲 05月27日
- VS2010+VMWare8+VisualDDK1.5.6 创建并调试你的第一个驱动程序 - 完全教程
- iOS开发工具——网络封包分析工具Charles
- Docker 使用方法总结之:容器的数据卷操作
- MyEclipse使用总结——MyEclipse10安装SVN插件
- 详解:若何让一个HTML元素的地区展谦齐屏? 05月27日
- 单链表找环