M
M
Mikha Pankratov2016-06-20 10:16:04
MySQL
Mikha Pankratov, 2016-06-20 10:16:04

How to correctly calculate the distance between objects?

Good afternoon, I
installed mysql 5.7 > I found ST_Distance_Sphere there, but I can’t figure out how to calculate the distance for everyone. In general, I have a table where I need to compare one user with the rest and display all who have a distance of no more than 10 miles.
I'm trying to )))

SELECT  *  FROM `profile` WHERE (ST_Distance_Sphere(
  (SELECT geo FROM profile WHERE user_id = 9972), 
    (SELECT geo FROM profile WHERE user_id > 200000)
))

Please direct me how to compare all with one.
field geo type point

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AxisPod, 2016-06-20
@AxisPod

MySQL learned to pass nested queries in a function? How do you imagine it. Make a selection with a normal join first, then do a WHERE. Here, in any case, each muscle will not build indexes for each muscle and you will have to bypass all the stored data.

O
Oleg Gamega, 2016-06-20
@gadfi

something you have is completely overhead, I somehow wrote a similar task on sqlite without built-in functions for working with geodata, nothing complicated, it worked quickly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question