# [LeetCode] Consecutive Numbers 连续的数字

+关注继续查看

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.

SELECT DISTINCT l1.Num FROM Logs l1
JOIN Logs l2 ON l1.Id = l2.Id - 1
JOIN Logs l3 ON l1.Id = l3.Id - 2
WHERE l1.Num = l2.Num AND l2.Num = l3.Num;

SELECT DISTINCT l1.Num FROM Logs l1, Logs l2, Logs l3
WHERE l1.Id = l2.Id - 1 AND l2.Id = l3.Id - 1
AND l1.Num = l2.Num AND l2.Num = l3.Num;

SELECT DISTINCT Num FROM (
SELECT Num, @count := IF(@pre = Num, @count + 1, 1) AS n, @pre := Num
FROM Logs, (SELECT @count := 0, @pre := -1) AS init
) AS t WHERE t.n >= 3;

SAP Spartacus SpartacusB2cConfigurationModule 的使用场景
SAP Spartacus SpartacusB2cConfigurationModule 的使用场景
22 0
SAP Spartacus b2b table，通过listService的table type字段来控制要加载的数据类型
SAP Spartacus b2b table，通过listService的table type字段来控制要加载的数据类型
27 0
02、前端基础之CSS
[toc] CSS介绍 CSS（Cascading Style Sheet，层叠样式表)定义如何显示HTML元素。 当浏览器读到一个样式表，它就会按照这个样式表来对文档进行格式化（渲染）。
1142 0
Confluence 6 为 Active Directory 配置一个 SSL 连接预要求

857 0
Windows下编译objective-C
Windows下编译objective-C 2011-08-31 14:32 630人阅读 评论(0) 收藏 举报 windowscocoa工具objective clibraryxcode   目录(?)[+]   Windows下编译objective-C http://www.
1290 0
Windows 8 和 Windows 8.1 中对插件和 ActiveX 的支持

963 0
+关注