8000 add : 180 · h-j-13/LeetCode-Database@3f8d386 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f8d386

Browse files
committed
add : 180
1 parent cbe1e86 commit 3f8d386

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Soulution/180. Consecutive Numbers.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# 180. Consecutive Numbers
2+
3+
Write a SQL query to find all numbers that appear at least three times consecutively.
4+
```
5+
+----+-----+
6+
| Id | Num |
7+
+----+-----+
8+
| 1 | 1 |
9+
| 2 | 1 |
10+
| 3 | 1 |
11+
| 4 | 2 |
12+
| 5 | 1 |
13+
| 6 | 2 |
14+
| 7 | 2 |
15+
+----+-----+
16+
```
17+
For example, given the above Logs table, 1 is the only number that appears consecutively for at least three times.
18+
```
19+
+-----------------+
20+
| ConsecutiveNums |
21+
+-----------------+
22+
| 1 |
23+
+-----------------+
24+
```
25+
26+
## 题目大意
27+
找出连续出现三次的数字
28+
29+
## SQL
30+
```SQL
31+
# Write your MySQL query statement below
32+
SELECT DISTINCT a.Num AS ConsecutiveNums
33+
FROM `Logs` a LEFT JOIN `Logs` b ON a.id + 1 = b.id
34+
LEFT JOIN `Logs` c on b.id + 1 = c.id
35+
WHERE a.Num = b.num AND b.num = C.num
36+
37+
```
38+
39+
值得注意的是,表名logs好像是sql的保留字(输入后会变深蓝) 使用 "`" 来将其声明为表名

0 commit comments

Comments
 (0)
0