SQL
All Top 50 SQL Interview Questions#34
Find Numbers Appearing at Least Three Times Consecutively in SQL
MediumAmazonInterview Question #34
Asked at AmazonGiven a `logs` table with `id` (autoincrementing) and `num`, write a SQL query to find all numbers that appear at least three times consecutively.
Input Table: logs
7 rows preview| id | num |
|---|---|
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 2 |
| 5 | 1 |
| 6 | 2 |
| 7 | 2 |
Expected Output Structure1 rows
| ConsecutiveNums |
|---|
| 1 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
PostgreSQL 15
Ready to execute
Click "Run Query" or press Ctrl + Enter to test your query.
Output will be verified against the test dataset.