
连续出现的数字(sql)
发布日期:2021-05-12 22:23:14
浏览次数:12
分类:精选文章
本文共 787 字,大约阅读时间需要 2 分钟。
表:Logs
+-------------+---------+
| Column Name | Type | +-------------+---------+ | id | int | | num | varchar | +-------------+---------+ id 是这个表的主键。
编写一个 SQL 查询,查找所有至少连续出现三次的数字。
返回的结果表中的数据可以按 任意顺序 排列。
查询结果格式如下面的例子所示:
Logs 表:
+----+-----+ | Id | Num | +----+-----+ | 1 | 1 | | 2 | 1 | | 3 | 1 | | 4 | 2 | | 5 | 1 | | 6 | 2 | | 7 | 2 | +----+-----+Result 表:
+-----------------+ | ConsecutiveNums | +-----------------+ | 1 | +-----------------+ 1 是唯一连续出现至少三次的数字。来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/consecutive-numbers我的解题:
select distinct(Num) as ConsecutiveNums from `Logs` as l where EXISTS( (select l.Num from ( select IF(count(Num)>=3,count(distinct(Num)),0) as dd from `Logs` as l2 where l2.Id >= l.Id and l2.Id < l.Id+3 ) as ff where ff.dd=1 ))
发表评论
最新留言
网站不错 人气很旺了 加油
[***.192.178.218]2025年05月02日 15时36分16秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
一文学会JVM常见参数设置+调优经验(JDK1.8)
2019-03-09
一文理解设计模式--命令模式(Command)
2019-03-09
VTK:可视化之RandomProbe
2019-03-09
block多队列分析 - 2. block多队列的初始化
2019-03-09
Java时间
2019-03-09
不编译只打包system或者vendor image命令
2019-03-09
MySQL
2019-03-09
The wxWindows Library Licence (WXwindows)
2019-03-09
leetcode——第203题——虚拟头结点
2019-03-09
【编程】C语言入门:1到 100 的所有整数中出现多少个数字9
2019-03-09
MySQL----基础及常用命令
2019-03-09
模拟集成:MOS管的工作区小误区(简单版)
2019-03-09
flink启动(二)
2019-03-09
前端开发进阶手册.pdf
2019-03-09
110.无限叠卡特效
2019-03-09
软件架构设计和MESH经验之谈
2019-03-09
redis持久化分析
2019-03-09
复杂指针解析
2019-03-09
打开word时424错误
2019-03-09