Advanced
Complex SQL Window Functions
Solve a complex data analysis problem using advanced SQL window functions.
📝 Nội dung Prompt
Given a hypothetical table 'user_sessions' containing columns: user_id, session_start (timestamp), session_end (timestamp), and page_views (int). Write a single SQL query to calculate the moving average of page_views over the previous 3 sessions for each user, ordered by time. Additionally, identify the session with the maximum duration for each user and rank the users by their total engagement time without using subqueries in the FROM clause. Explain the execution plan and performance implications of your query.