180. Consecutive Numbers
2017-04-16 16:08
120 查看
Write a SQL query to find all numbers that appear at least three times consecutively.
For example, given the above
Subscribe to see which companies asked this question.
MySQL:
# Write your MySQL query statement below
select
distinct
a.Num as ConsecutiveNums
from
Logs a,
Logs b,
Logs c
where
a.Id = b.Id + 1
and a.Id = c.Id + 2
and a.Num = b.Num
and a.Num = c.Num
;
+----+-----+ | Id | Num | +----+-----+ | 1 | 1 | | 2 | 1 | | 3 | 1 | | 4 | 2 | | 5 | 1 | | 6 | 2 | | 7 | 2 | +----+-----+
For example, given the above
Logstable,
1is the only number that appears consecutively for at least three times.
Subscribe to see which companies asked this question.
MySQL:
# Write your MySQL query statement below
select
distinct
a.Num as ConsecutiveNums
from
Logs a,
Logs b,
Logs c
where
a.Id = b.Id + 1
and a.Id = c.Id + 2
and a.Num = b.Num
and a.Num = c.Num
;
相关文章推荐
- 浪潮英星NF 180 安装redhat 的企业RHEL as 4 遇到的问题
- SGU 180
- windows 2008 r2 180 days evaluation keys
- SGU - 180 (树状数组+离散化)
- Waiting 180 more seconds for 1 worker threads to finish
- 关于GDAL180中文路径不能打开的问题分析与解决
- 逆序数poj 2299 Ultra-QuickSort sgu 180 Inversions
- python apply()函数 分类: python学习 2014-07-30 15:33 180人阅读 评论(0) 收藏
- 2014年工作中遇到的20个问题:161-180
- 2013年工作中遇到的20个问题(Bug):161-180
- iOS将image转90,180,270度的方法
- [国嵌攻略][180][加密传输优化]
- 180. Consecutive Numbers
- Codeforces Round #180 (Div. 2)-A. Snow Footprintsv
- 算法笔记_180:历届试题 国王的烦恼(Java)
- Java面试题集(151-180)
- 入门话题1. 在Web中控制图的显示外观?把一张500*800 的图, 显示成180*110 的小图.
- 图片翻转180,镜像的简单实现方法
- teleships 旋屏180
- DL 180 服务器调整BIOS设置,禁用板载阵列卡