当前位置:网站首页>力扣(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
;
边栏推荐
- 【Paper】2017_ Research on coordinated control method of underwater vehicle formation marine survey
- Unity Logitech steering wheel access
- 一条命令运行rancher
- Connect to the database and run node JS running database shows that the database is missing
- A virtual reality secret room escape adventure, let you see Technology Singapore
- Arsenal Stadium Tour - take you to the front and back of Arsenal Stadium
- Collective system
- Method of applying for code signing certificate by enterprise
- Spring Festival Tourism Strategy: welcome the new year in Bangkok, Thailand
- Connect to the database and run node JS running database shows that the database is missing
猜你喜欢

Harbor API 2.0 query

This connection is not a private connection this website may be pretending to steal your personal or financial information

Why does the computer have no network after win10 is turned on?
![[fpga] implementation of IIC read / write EEPROM](/img/6a/36e9355058a90d98cffafcbaa1930b.png)
[fpga] implementation of IIC read / write EEPROM

深度学习------不同方法实现Inception-10
![[UAV] kinematic analysis from single propeller to four rotor UAV](/img/32/1a88b102f832ffbbc1a7e57798260a.jpg)
[UAV] kinematic analysis from single propeller to four rotor UAV

Oracle-数据的基本操作

Unity3d realizes Google Digital Earth

Create a simple battle game with photon pun

HTC vive cosmos development - handle button event
随机推荐
0 foundation starts self-study unit notes control direction becomes larger
深度学习------不同方法实现Inception-10
PBR material: basic principle and simple fabrication
The subsystem implementing transaction persistence in DBMS is ()
Foreign SSL certificate
Deeply understand the function calling process of C language
One interview question a day the difference between B tree and b+ tree
How to apply for SSL certificate from the manufacturer
One interview question and one joint index every day
一条命令运行rancher
【Paper】2021_ Analysis of the Consensus Protocol of Heterogeneous Agents with Time-Delays
Unity script life cycle and execution sequence
力扣2049:统计最高分的节点数目
力扣周赛293题解
Recommended cultural landmarks of these tourist attractions in Bangkok
Beanfactory creation process
The difference between get and post requests
[control] multi agent system summary. 4. control agreement.
Tcp/ip protocol details Volume I (Reading Guide)
Window10 jar double click to run without response