博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
180. Consecutive Numbers (Medium)
阅读量:4520 次
发布时间:2019-06-08

本文共 627 字,大约阅读时间需要 2 分钟。

Source:

Description:

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.

+-----------------+| ConsecutiveNums |+-----------------+| 1               |+-----------------+

 

Solution:

select distinct l1.numfrom Logs l1     join Logs l2 on l1.id=l2.id-1     join Logs l3 on l1.id=l3.id-2where l1.num=l2.num and l2.num=l3.num

 

转载于:https://www.cnblogs.com/sixu/p/6884817.html

你可能感兴趣的文章
java 格式化字符串
查看>>
[.Net]轻量ORM——Dapper
查看>>
语言基础
查看>>
C# : 操作Word文件的API - (将C# source中的xml注释转换成word文档)
查看>>
C#中字符串转换成枚举类型的方法
查看>>
psplash
查看>>
git的安装和简单使用
查看>>
20151024-1025-威海-第5届全国高校软件工程专业教育年会参会总结
查看>>
Airplace平台
查看>>
TinyOS实例介绍
查看>>
css hack 尽我所见
查看>>
[转]ORACLE联机日志文件无故全部消失
查看>>
Javascript基础学习12问(四)
查看>>
[原]VS2012入门图文教程——第一个程序Hello World
查看>>
#pragma once 与 #ifndef 解析(转载)
查看>>
swift 数据存储
查看>>
Objective-C内存管理教程和原理剖析(三)
查看>>
最大子数组
查看>>
pyton random 模块
查看>>
.bat以管理员身份运行
查看>>