Repeat Gate Entries Within a Day
Problem
A parking garage logs every time a vehicle passes through the entry gate.
Table: gate_events
| Column Name | Type |
|-------------|----------|
| vehicle_id | int |
| entered_at | datetime |
| lane | varchar |
(vehicle_id, entered_at) is the primary key for this table. Each row records a single gate entry by a vehicle.
Write a query to find the vehicle_id of every vehicle that entered the gate at least twice within a 24-hour window. Two entries exactly 24 hours apart count as inside the window.
Return the result in any order.
Tables
Example rows — the live problem includes the full dataset.
| vehicle_id | entered_at | lane |
|---|---|---|
| 3 | 2021-01-06 03:30:46 | north |
| 3 | 2021-01-06 03:37:45 | north |
| 7 | 2021-06-12 11:57:29 | south |
Expected output
Your answer should return 3 rows with the columns vehicle_id.
Starter code (SQL)
SELECT *
FROM gate_events;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