Skip to content
Advertisement

Finding the most visited place at a particular time in SQL

I have a user’s table that has info about user_id, places user purchased tickets, and the time user had purchased the ticket.

Users:

I want to add a new column that shows the user’s most visited place at the time of purchasing ticket. The table would like (Snowflake):

Advertisement

Answer

You want to use a WINDOW version of COUNT to get the “prior rows count” and then join to all the prior counted rows, and filter out the “best” via a QUALIFY

*this sql has not been run.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement