I work with web click data, and just look for the last page_name with a visit to user_id (by timestamp). Using the code below, user_id is repeated and page_name is shown, with sorted downstream. However, I would like recent_click to always = 1. The request, when it is filled, will be used as a subquery in a larger request.
Here is my current code:
SELECT user_id, page_name, row_number() over(partition by session_id order by ts desc) as recent_click from clicks_data; user_id | page_name | recent_click
source share