Skip to content
Advertisement

Counting unique values within a time window

I have data that looks like (over 100.000 rows):

What I would like:

Explanation

CONTEXT

I want to find out how many people (person) are working in the same location (Location) by looking at a time window (timestamp) of max 10 minutes and checking whether a person is really working simultaneously or just taking over their shift within that frame. I get the data with a SQL query and could parse it using either SQL or Python. SQL is preferred.

TRIED SOLUTIONS

  • Grouping by location, timestamp leads to ‘hard cuts’
  • Probably need an so-called window function. But after sorting on timestamp, how do I prevent Locations mixing up?

Note: If easier, I can also try to do this in Python, but I rather not given the size of the dataset and my limited options to do it in the cloud.

Advertisement

Answer

This should work

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