Skip to content
Advertisement

(SQL) Create Table with Distances from Separate Table with XY Coordinates

I am trying to create a table that will have unique distances between slot machines based on the following dataset.

enter image description here

I know I first need to calculate my distances and the only way I currently know how would be to use the following code:

But this obviously only returns the distance between the first two machines. How do I calculate the distances between all of the machines? Then, how would I properly make sure each distance is unique?

What would be the easiest way to do this in SQL?

Thank you for any help!

Advertisement

Answer

You would simply use a cross join:

If you wanted the distance between two machines only calculated once, then add an inequality:

EDIT:

If you want “unique” distances, you could use:

This doesn’t seem useful to me, but it does provide a list of unique distances for each machine.

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