当前位置:网站首页>力扣(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
;
边栏推荐
- 力扣周赛293题解
- Unreal 4 learning notes - Animated Montage
- Geotrustov wildcard
- 力扣589:N 叉树的前序遍历
- One interview question a day the difference between B tree and b+ tree
- Li Kou 2049: count the number of nodes with the highest score
- C # Foundation
- Force buckle 59 Spiral matrix II
- 力扣27. 移除元素
- SCM learning notes: interrupt learning
猜你喜欢

What is multimodal interaction?

Unreal 4 learning notes - set player birth point

【Paper】2013_ An efficient model predictive control scheme for an unmanned quadrotor helicopter

力扣27. 移除元素

Free travel recommendation in Bangkok: introduction to the Mekong River in Bangkok

What to do when the alicloud SSL certificate expires

PBR material: basic principle and simple fabrication

Unity automatic pathfinding

Issue SSL certificate with IP address

EasyRecovery数据恢复软件 恢复了我两年前的照片视频数据
随机推荐
A collection of errors encountered in machine learning with unity
Unity download and installation website
Software digital signature certificate
[fpga] implementation of IIC read / write EEPROM
Qos(Quality of Service)
redis集群概念
Unity enables simple music visualization
Photon pun refresh hall room list
Webots notes day 2
Solution to 293 problems in the week of Li Kou
Tcp/ip protocol details Volume I (Reading Guide)
[UAV] kinematic analysis from single propeller to four rotor UAV
【Paper】2015_ Active fault-tolerant control system design with trajectory re-planning against actuator
Cheap SSL certificate abroad
Unity Logitech steering wheel access
Have a heart beating Valentine's day in Singapore
One interview question and one joint index every day
Deeply understand the function calling process of C language
Unity3d Google Earth
Pourquoi l'ordinateur n'a - t - il pas de réseau après l'ouverture du Hotspot win10?