Clocked Hours from Swipe In/Out Pairs
Problem
**[Classic — asked at multiple companies]**
An office building logs badge swipe events (IN/OUT, always properly paired).
Calculate each employee's **total hours worked** by pairing the nth IN with the nth OUT.
Return `employee_id` and `total_hours` (rounded to 2 dp), ordered by employee.
Tables
Example rows — the live problem includes the full dataset.
badge_events
| event_id | employee_id | event_time | event_type |
|---|
Expected output
Your answer should return 2 rows with the columns employee_id, total_hours.
Starter code (SQL)
SELECT *
FROM badge_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