Generate Run-Length ID With SQL
What is run-length ID? Sometimes during analysis work, you need to group consecutive sequence of values into different “runs”, and calculate metrics for each run. For example: Given a time series recording some entity’s state, you want to calculate on average, how long does an entity stay in a particular state. Or a more specific example: Given a series of event data of several users, you want to group the users’ events into sessions with a session cut-off threshold of your choice ...