First of all, note that your definition of “within 5 minutes of each other” does not determine the only solution and that your (MIN () + MAX ()) / 2 is not average, but simply average and minimal. You can search for AVG () in your subqueries.
Secondly, you do not get results within 5 seconds of each other, but records whose longitude and latitude are no more than 10 seconds (which diagonally can be closer to 14).
In mysql, you can use session variables such as:
SET @avg_lat := (SELECT round(avg(LATITUDE)) FROM STATION WHERE DISTRICT_ID = '110' AND NAME LIKE 'Vancouver%'); SET @avg_long := (SELECT round(avg(LONGITUDE)) FROM STATION WHERE DISTRICT_ID = '110' AND NAME LIKE 'Vancouver%'); SELECT NAME FROM STATION WHERE DISTRICT_ID = '110' AND pow( LATITUDE-@avg _lat,2)+pow( LONGITUDE-@avg _long,2)<25 ORDER BY LATITUDE
Despite the fact that this is optional (as in the request written above, both variables occur only once).
EDIT: Oh, skip the question. This is the center radius - so replace 25 with 100 (and until it is decided whether you want to use less or equal). Also, if the center is the center of the bounding box, your (min () + max ()) / 2 is the correct formula, not my suggestion. However, the “center of all places” is a bit vague, so I leave my answer (it’s easy to change).
EDIT2: just noticed that the units in my request are not correct, if the latitude is stored in centimines, then the comparison should also be in centimines (10 * 100) ^ 2 = 1000000
And finally, your decision to stick with (min () + max ()) / 2 will lead to examples where you can have one line that is far from the maximum and minimum, which may cause the query to skip any of the results (and may to happen, as a rule, all locations with similar names are next to each other, but it’s not uncommon to have another place starting with the same name, which is an isolated place away from a conglomerate of locations).
As for the 5-minute area, to be completely accurate, it’s better to say that it is a 10x10 minute area to return requests.
EDIT3: The above formula for distance is not very accurate if you move away from the equator. Here is the best approximation of distance formula For serious work you may need something like this