Bigquery resources exceeded during query execution – optimization

I have got a problem with this query. SELECT event_date, country, COUNT(*) AS sessions, AVG(length) AS average_session_length FROM ( SELECT country, event_date, global_session_id, (MAX(event_timestamp) – MIN(event_timestamp))/(60 * 1000 * 1000) AS length FROM ( SELECT user_pseudo_id, event_timestamp, country, event_date, SUM(is_new_session) OVER (ORDER BY user_pseudo_id, event_timestamp) AS global_session_id, SUM(is_new_session) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp)…

Details