Skip to content

Commit ac51876

Browse files
committed
Merge branch 'master' of github.com:krystism/leetcode
2 parents 1d45be1 + 497b97e commit ac51876

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

database/ConsecutiveNumbers/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ For example, given the above Logs table, 1 is the only number that appears conse
2020

2121
使用自连接,然后一一和上一个比较,最后分组过滤即可
2222
```sql
23-
select log1.Num from Logs log1 join Logs log2 on log1.Id + 1 = log2.Id and log1.Num = log2.Num group by log1.Num having count(log1.Num) >= 2;
23+
select log1.Num from Logs log1
24+
join Logs log2
25+
on log1.Id + 1 = log2.Id and log1.Num = log2.Num
26+
group by log1.Num
27+
having count(log1.Num) >= 2;
2428
```
2529

2630
结果超时, 可能是分组导致的。
@@ -30,7 +34,9 @@ select log1.Num from Logs log1 join Logs log2 on log1.Id + 1 = log2.Id and log1.
3034
还是使用自连接,不过为了避免group开销,直接使用三个表连接,分别指向Id, Id + 1, Id + 2,并分别让Num相等即可
3135

3236
```sql
33-
select distinct a.Num from Logs a, Logs b,Logs c where a.Id=b.Id+1 and a.Num=b.Num and b.Id=c.Id+1 and b.Num=c.Num;
37+
select distinct a.Num
38+
from Logs a, Logs b,Logs c
39+
where a.Id=b.Id+1 and a.Num=b.Num and b.Id=c.Id+1 and b.Num=c.Num;
3440
```
3541

3642
## Solution 3

0 commit comments

Comments
 (0)