0
A
回答
0
无论距离函数使用的是(用于短距离在数千里简单的直线毕达哥拉斯,或者大圆公式任何东西),
Select * from table
where [DistanceFunction]
(Latitude, Longitude, FiumicinoLatitude, FiumicinoLongitude) =
(Select Max([DistanceFunction]
(Latitude, Longitude, FiumicinoLatitude, FiumicinoLongitude))
From table)
,如果你需要找到机场最远从(并不总是菲乌米奇诺)的一些任意的机场,那么,假设@code是任意机场机场代码:
Select * from table t
join table r on r.code = @code
where [DistanceFunction]
(t.Latitude, t.Longitude, r.Latitude, r.Longitude) =
(Select Max([DistanceFunction]
(Latitude, Longitude, r.Latitude, r.Longitude))
3
只要你可以下面的SQL查询运行
SELECT *, (3959 * acos(cos(radians(37)) * cos(radians(lat)) * cos(radians(lng) - radians(-122)) + sin(radians(37)) * sin(radians(lat)))) AS distance FROM table_name;
其中;
要按公里而非英里搜索距离,与6371.
取代3959是你的输入纬度
-122是你输入的经度
LAT是表其中包含机场纬度列名值
LNG是包含机场经度值表的列名
更多细节回答:Creating a store locator
0
SQL SERVER
,如果你正在努力寻找从每个机场最远的一个,您将需要一个函数。但既然你说FCO,我就是为FCO做的。
您正在使用哪种类型的数据库--temp table for testing
select 'FCO' as code, 'Fiumicino' as name, 'Rome' as city, 'Italy' as country, 41.7851 as latitude, 12.8903 as longitude into #airports
union all
select 'VCE', 'Marco Polo','Venice','Italy',45.5048,12.3396
union all
select 'NAP', 'capodichino','Naples','Italy',40.8830,14.2866
union all
select 'CDG', 'Charles de Gaulle','Paris','France',49.0097,2.5479
--create a point from your LAT/LON
with cte as(
select
*,
geography::Point(latitude,longitude,4326) as Point --WGS 84 datum
from #airports),
--Get the distance from your airport of interest and all others.
cteDistance as(
select
*,
Point.STDistance((select Point from cte where code = 'FCO')) as MetersToFiuminico
from cte)
--this is the one that's furthest away. Remove the inner join to see them all
select d.*
from
cteDistance d
inner join(select max(MetersToFiuminico) as m from cteDistance where MetersToFiuminico > 0) d2 on d.MetersToFiuminico = d2.m
相关问题
- 1. 点击其他
- 2. ,而忽略其他任何
- 3. UINavigationController在任何其他类
- 4. 任何其他GXT主题?
- 5. C#和跟踪任何其他选项?
- 6. 获取标题图像溢出其他任何其他
- 7. 和其他
- 8. 插入MAX()+ 1和其他值
- 9. 比较向量值:1个元素与其他所有其他
- 10. iOS 5 - 1自定义UINavigationBar不同于其他所有其他
- 11. geochart:向其添加html注释或其他任何其他替代图表
- 12. 调用与其他任务
- 13. StringVar DoubleVar和其他
- 14. requirejs和其他库
- 15. 显示DIV后1链接和其他DIV被点击
- 16. 如何对`NaN`进行排序,使其大于任何其他数字,并等于任何其他`NaN`?
- 17. 选择记录,其中ID是在其他表和状态= 1
- 18. jquery点击其他功能
- 19. nginx的其他地点
- 20. jQuery点击其他元素
- 21. 其他
- 22. XSLT的子节点和其他文本
- 23. 隐藏比我有其他点击其他的div ... jQuery的
- 24. 禁用其他按钮点击其他按钮
- 25. 其他SqlDataReader需要关闭,虽然我已经关闭了其他任何其他
- 26. 任何其他图标字符,如'⚠️'
- 27. 任何其他方式做动画?
- 28. 与任何其他的SQL语法
- 29. ksoap2 v prefixo任何其他前缀
- 30. 用SYS表处理任何其他表
? – anakic
你能告诉我们你已经尝试了什么,并解释它为什么没有解决你的问题? – dfundako
我删除了不兼容的数据库标签。为您正在使用的数据库添加一个。 –