Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. with t1 as (
  2.  
  3. SELECT *,
  4. lag(timestamp) over(partition by user_id order by timestamp) as timestamp_lag,
  5. if(TIMESTAMP_DIFF(timestamp, lag(timestamp) over(partition by user_id order by timestamp),minute)<30,0,1) as session_start
  6. FROM `table_name`
  7.  
  8. )
  9.  
  10. select *,
  11. sum(session_start) over(partition by user_id order by timestamp) as session_number
  12. from t1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement