# 180. Consecutive Numbers(SQL)

### Solution 1:

复制三个表格做内交，想象一下三张卡片，第二张比第一张往下位移1格，第三张比第一张往下位移2格，根据`num`相等相交出来的一行一定是连续重复了三次的数

### Solution 2:

建立三个表格，加上4个所有的限制条件，即为结果

```sql
# Write your MySQL query statement below
select distinct l1.Num ConsecutiveNums from Logs l1
join Logs l2 on l1.Id = l2.Id-1
join Logs l3 on l1.Id = l3.Id-2
where l1.Num = l2.Num and l2.Num = l3.Num;

# 或者另一种方法
select distinct l1.Num 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;
```

{% hint style="danger" %}
从这道题可以看出命名的规则比较明显，无论是表格还是列的命名都直接紧跟后面即可，表格重命名可以在前面的**select**关键词后面直接用
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://r24zeng.gitbook.io/leetcode-notebook/bu-chong-4060-dao/180.-consecutive-numbers-sql.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
