如图有两张表,小区表(xiaoqu)和地铁表(metro),现在小区表里面小区附近的地铁站(图片中红色字段)是空的。想批量完善这个字段,求助。
附近的定义是:离小区最近,并且在1000米以内的一个地铁站。
例如:北京的华腾园小区,附近1000米有双井和劲松两个站,但是劲松距离较近,所以华腾园那一行对应的就是劲松站。
目前已经自定义了两个经纬度之间距离的函数。getdistance(纬度1,经度1,纬度2,经度2),函数代码如下:
-- getdistance(Lat1 ,Lon1,Lat2 ,Lon2)
BEGIN
DECLARE
dis DOUBLE ;
SET dis = ACOS(
SIN((Lat1 * 3.1415) / 180) * SIN((Lat2 * 3.1415) / 180) + COS((Lat1 * 3.1415) / 180) * COS((Lat2 * 3.1415) / 180) * COS(
(Lon1 * 3.1415) / 180 - (Lon2 * 3.1415) / 180
)
) * 6370996.81;
RETURN dis ;
END
My idea is: get the target point coordinates -> Use a certain range r to check which subways in the subway table are in r. If there are, compare the distances. If r is not increased, repeat until the r distance exceeds the maximum range -> ;Finish.
I think the key to efficiency lies in calculating and comparing distances.
I think this should not be implemented using
SQL
.SQL
去实现。我去做的话:
获取
小区
信息,获取属于哪座城市
。用
SQL
把当前城市地铁数据
搜出来。然后可以用各种
If I do it:算法
community
information and whichcity
it belongs to.Use
🎜SQL
to search forcurrent city subway data
.algorithms
(or rules, such as your method above) to calculate the nearest subway. 🎜🎜 🎜 🎜🎜SQL should be used to store and obtain data, and should not carry too many logical functions🎜🎜