Skip to content
Advertisement

SQL aggregation based on time and location for Sankey graph

I have a situation where I’m trying to get data to populate a Sankey graph.

I have the data with timestamp and the location of the person when captured by the system.

The normal case is when a person location changes and in that case, “from” should be that location and “to” should be that person’s next entry provided it’s less than 2h difference from “from”.

Original data:

Result required in the following way (or similar):

Can you give me an idea of how can I get such result in SQL? I’m using BigQuery, but I believe standard SQL should do the job.

Thanks,

Diogo

Advertisement

Answer

Consider below

if applied to sample data as in your question

enter image description here

output is

enter image description here

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