跳到主要内容

180.连续出现的数字

序号题目难度
180题目链接中等

题目大意​

找出所有至少连续出现三次的数字。

返回的结果表中的数据可以按 任意顺序 排列。

表:Logs

Column NameType
idint
numvarchar

在 SQL 中,id 是该表的主键。 id 是一个自增列。

示例​

输入​

Logs 表:

idnum
11
21
31
42
51
62
72

输出​

Result 表:

ConsecutiveNums
1

解释:1 是唯一连续出现至少三次的数字。

参考答案​

select
distinct t1.Num as ConsecutiveNums
from Logs as t1
join Logs as t2
on t1.Id = t2.Id - 1
join Logs as t3
on t2.Id = t3.Id - 1
where t1.Num = t2.Num
and t2.Num = t3.Num
;