AnalystPath

Triple Consecutive Sensor Codes

SQLMediumMid level~15 min

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_nocode
17
27
37

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

Related SQL questions