Description
Write a SQL query to find all numbers that appear at least three times consecutively in the logs table. Return distinct num. **Output columns (in order):** num
Table:
logs| Column | Type |
|---|---|
| id | INT |
| num | INT |
Examples
Input:
CREATE TABLE logs (id INT, num INT); INSERT INTO logs VALUES (1, 1), (2, 1), (3, 1), (4, 2), (5, 1), (6, 2), (7, 2);Output:
1Explanation:
Number 1 appears 3 times consecutively at ids 1, 2, 3. Number 2 only appears twice consecutively at most (ids 6, 7).
Input:
CREATE TABLE logs (id INT, num INT); INSERT INTO logs VALUES (1, 5), (2, 3), (3, 3), (4, 3), (5, 3), (6, 7), (7, 7), (8, 7), (9, 9);Output:
3
7Explanation:
Number 3 appears 4 times consecutively (ids 2-5) and number 7 appears 3 times consecutively (ids 6-8). Both qualify as appearing at least 3 times consecutively.
Input:
CREATE TABLE logs (id INT, num INT); INSERT INTO logs VALUES (1, 8), (2, 4), (3, 4), (4, 6), (5, 6), (6, 6), (7, 6), (8, 2), (9, 2), (10, 8);Output:
6Explanation:
Number 4 appears only 2 times consecutively (ids 2-3), number 2 appears only 2 times consecutively (ids 8-9), but number 6 appears 4 times consecutively (ids 4-7), meeting the requirement of at least 3 consecutive occurrences.
Constraints
- •
Numbers must be consecutive by id