如何使用 ST_Distance_Sphere 从 MySQL 中仅获取一列
How to get only one column from MySQL with ST_Distance_Sphere
我有一个 table,其中包含城市列表和 GPS 坐标,例如:
id, name, lat, lon
我正在搜索以获取最近的城市
select
name,
ST_Distance_Sphere(point(lon, lat), point('20.073602', '49.937056') )/1000 as distance
from city
order by distance asc LIMIT 1;
但是 如何从该查询中仅接收一个 'city' 字段(一列) 作为结果而没有第二列,即距离?
这是我的SQLfiddle:https://www.db-fiddle.com/f/hdshw2KCjNZrXZoKQQgoKR/1
您可以将表达式直接放在 order by
子句中
select
name
from city
order by ST_Distance_Sphere(point(lon, lat), point('20.073602','49.937056') )/1000 asc
limit 1;
我有一个 table,其中包含城市列表和 GPS 坐标,例如:
id, name, lat, lon
我正在搜索以获取最近的城市
select
name,
ST_Distance_Sphere(point(lon, lat), point('20.073602', '49.937056') )/1000 as distance
from city
order by distance asc LIMIT 1;
但是 如何从该查询中仅接收一个 'city' 字段(一列) 作为结果而没有第二列,即距离?
这是我的SQLfiddle:https://www.db-fiddle.com/f/hdshw2KCjNZrXZoKQQgoKR/1
您可以将表达式直接放在 order by
子句中
select
name
from city
order by ST_Distance_Sphere(point(lon, lat), point('20.073602','49.937056') )/1000 asc
limit 1;