当前位置:网站首页>力扣(LeetCode)180. 连续出现的数字(2022.06.29)
力扣(LeetCode)180. 连续出现的数字(2022.06.29)
2022-06-30 04:55:00 【ChaoYue_miku】
表:Logs
±------------±--------+
| Column Name | Type |
±------------±--------+
| id | int |
| num | varchar |
±------------±--------+
id 是这个表的主键。
编写一个 SQL 查询,查找所有至少连续出现三次的数字。
返回的结果表中的数据可以按 任意顺序 排列。
查询结果格式如下面的例子所示:
示例 1:
输入:
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/problems/consecutive-numbers
方法一:使用DISTINCT
MySQL提交内容:
# Write your MySQL query statement below
SELECT DISTINCT
l1.Num AS ConsecutiveNums
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
;
边栏推荐
- Easyrecovery data recovery software recovers my photo and video data two years ago
- 0 foundation starts self-study unit notes control direction becomes larger
- Unity3d Google Earth
- Foreign SSL certificate
- What to do when the alicloud SSL certificate expires
- IIS request SSL certificate
- Winter vacation parent-child tour, these new york attractions are not only fun but also knowledge
- Cheap SSL certificate abroad
- Introduction to some representations, neighbors and degrees of Graphs
- 【Paper】2019_ Distributed Cooperative Control of a High-speed Train
猜你喜欢

Exploration of unity webgl

力扣977. 有序数组的平方

力扣27. 移除元素
![[UAV] kinematic analysis from single propeller to four rotor UAV](/img/32/1a88b102f832ffbbc1a7e57798260a.jpg)
[UAV] kinematic analysis from single propeller to four rotor UAV

力扣209. 长度最小的子数组

HTC vive cosmos development - handle button event

力扣59. 螺旋矩阵 II

Connect to the database and run node JS running database shows that the database is missing

力扣704. 二分查找

【Paper】2015_ Active fault-tolerant control system design with trajectory re-planning against actuator
随机推荐
Easyrecovery data recovery software recovers my photo and video data two years ago
One interview question a day - the underlying implementation of synchronize and the lock upgrade process
amd锐龙CPU A320系列主板如何安装win7
Collective system
Unity a* road finding force planning
Unity download and installation website
Connect to the database and run node JS running database shows that the database is missing
brew安装nvm报nvm command not found解决方案
Unity is associated with vs. there is a compiler problem when opening
【Paper】2019_ Consensus Control of Multiple AUVs Recovery System Under Switching Topologies and Time D
Difference between request forwarding and redirection
Dual domain SSL certificate
SSL update method
Singapore must visit these scenic spots during the Spring Festival
为什么win10开热点后电脑没有网络?
The subsystem implementing transaction persistence in DBMS is ()
The difference between get and post requests
力扣209. 长度最小的子数组
2021-03-16
Unity3d Google Earth