sql 180.连续数字(第1个).sql

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 180.连续数字(第1个).sql相关的知识,希望对你有一定的参考价值。

# Write your MySQL query statement below

SELECT DISTINCT L1.Num AS ConsecutiveNums
FROM Logs AS L1 
JOIN Logs AS L2 ON L1.Num = L2.Num
JOIN Logs AS L3 ON L2.Num = L3.Num
WHERE L1.id = L2.id + 1 and L2.id = L3.id + 1

#{"headers": {"Logs": ["Id", "Num"]}, "rows": {"Logs": [[1, 1], [2, 1], [3, 1], [4, 2], [5, 1], [6, 2], [7, 2]]}}
#{"headers": {"Logs": ["Id", "Num"]}, "rows": {"Logs": [[1, 1], [2, 1], [3, 1], [4, 2], [5, 1], [6, 1], [7, 1]]}}
#注意去重
# Write your MySQL query statement below
select distinct(Num) as ConsecutiveNums
from (
    select Num, 
        @count := IF (@prev_num = Num, @count +1,1) as ct,
        @prev_num := Num as n
    from Logs, (select @count := 1, @prev_num := NULL) r
) as N
where ct >= 3

以上是关于sql 180.连续数字(第1个).sql的主要内容,如果未能解决你的问题,请参考以下文章

sql 180.连续数字(第1个).sql

sql 180.连续数字(第1个).sql

sql 180.连续数字(第1个).sql

sql 180.连续数字(第1个).sql

sql 180. 连续出现的数字

180. 连续出现的数字