Skip to content
Advertisement

Calculating distance using geometry of x and y location in SQL

I’m using SQL Server and I need to calculate the distance between the x and y of a frame and the previous x and y of a frame where the day, team, and member are all the same. Currently, I have this code that works but doesn’t accomplish what I need. I’m getting every distance permutation of the x and y location where the day, team, and member are all the same.

I need help to incorporate frames into the query so that I get the N+1 Frame x and y location minus the N Frame x and y location.

I also may deal with NULL x and y values so if it’s possible to add this to the query too.

Ultimately I want to track the distance of every member throughout the day, frame by frame.Later, I’ll add up each member’s total distance for the day.

Advertisement

Answer

CTE1 and CTE2 are used to improve readability of the query.

Output:

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