你能告诉我如何连接两个表,当我想从表1中获得所有店铺时,基于表2中有自己的geo_lat和geo_long的特定city_id?我想让我的店铺半径25公里内的所有店铺。
表一-商店: shop_name,商店描述,town_id
表二-城市: city_id,city_name,geo_lat,geo_long
我尝试了很多示例和方法,但都没有结果。
我找到了这个距离的代码:
SELECT
id, (
3959 * acos (
cos ( radians(78.3232) )
* cos( radians( lat ) )
* cos( radians( lng ) - radians(65.3234) )
+ sin ( radians(78.3232) )
* sin( radians( lat ) )
)
) AS distance
FROM markers
HAVING distance < 30
ORDER BY distance
LIMIT 0 , 20;我将非常感谢您的每一个答案。非常感谢。
发布于 2015-04-20 22:25:43
select s.shop_name, s.shop_description, s.town_id, c.city_id, c.city_name, c.geo_lat, c.geo_long from shops s
right join cities c on c.city_id = s.town_id
and (
3959 * acos (
cos ( radians(78.3232) )
* cos( radians(c.geo_lat ) )
* cos( radians( c.geo_long ) - radians(65.3234) )
+ sin ( radians(78.3232) )
* sin( radians( c.geo_lat ) )
)
) <= 25
where c.city_name = 'Prague'https://stackoverflow.com/questions/29750106
复制相似问题