Measure time since the prior event.
Section: Time-series patterns
Detect gaps between events
sql
sql
SELECT user_id,
event_time,
event_time - LAG(event_time) OVER (
PARTITION BY user_id
ORDER BY event_time
) AS time_since_prev
FROM user_events;Explanation
The exact subtraction syntax varies by dialect, but the window pattern stays the same.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Time-series patterns