Skip to content

Commit c7ef3f0

Browse files
authored
Merge pull request #21 from JinkeCao/master
modified: MySQL/consecutive-numbers.sql
2 parents 6ddbcdb + e9c31a0 commit c7ef3f0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

MySQL/consecutive-numbers.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# For example, given the above Logs table, 1 is the only number that appears consecutively for at least three times.
1818
#
1919

20+
# Solution 1
2021
# Write your MySQL query statement below
2122
SELECT DISTINCT(Num) AS ConsecutiveNums
2223
FROM (
@@ -27,3 +28,8 @@ FROM (
2728
FROM Logs y, (SELECT @counter:=1, @prev:=NULL) vars
2829
) sq
2930
WHERE how_many_cnt_in_a_row >= 3
31+
32+
# Solution 2
33+
SELECT DISTINCT l1.Num as ConsecutiveNums
34+
FROM Logs l1, Logs l2, Logs l3
35+
WHERE l1.Id + 1 = l2.Id AND l2.Id + 1 = l3.Id AND l1.Num = l2.Num AND l2.Num = l3.Num

0 commit comments

Comments
 (0)