Triple Consecutive Sensor Codes
Problem
A machine records a status code on every tick. Ticks are numbered sequentially.
Table: `tick_log`
| Column | Type |
|----------|------|
| tick_no | int |
| code | int |
`tick_no` is the primary key and increases by 1 with no gaps.
Write a query that finds every status `code` that appears in **at least three ticks in a row**. Return the distinct codes in a column named `repeated_code`, in any order.
Tables
Example rows — the live problem includes the full dataset.
tick_log
| tick_no | code |
|---|---|
| 1 | 7 |
| 2 | 7 |
| 3 | 7 |
Expected output
Your answer should return 1 row with the columns repeated_code.
Starter code (SQL)
SELECT *
FROM tick_log;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock