Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with t1 as (
- SELECT *,
- lag(timestamp) over(partition by user_id order by timestamp) as timestamp_lag,
- if(TIMESTAMP_DIFF(timestamp, lag(timestamp) over(partition by user_id order by timestamp),minute)<30,0,1) as session_start
- FROM `table_name`
- )
- select *,
- sum(session_start) over(partition by user_id order by timestamp) as session_number
- from t1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement