Dev.to
7/14/2026

SQLazy: Account-based Grouping with Sequence Number Reset on Gaps Exceeding 1 Hour
Short summary
A SQL tutorial demonstrating how to group records by account and assign sequence numbers that reset when the time gap between consecutive events exceeds one hour. The author uses SQLazy's step-by-step DSL (sort, segment, compute) and then compiles it into equivalent native SQL using LAG and ROW_NUMBER window functions. Includes sample input/output data.
- •Problem: assign per-account sequence numbers that reset on gaps > 1 hour
- •SQLazy DSL approach: sort, segment by time gap, compute row number per group
- •Generated SQL uses LAG for gap detection and ROW_NUMBER for sequencing
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



