此查询工作正常,但我想在此查询中使用MIN
函数,因为我只想要一个距离给定当前位置的距离最近的工作站。
select *
from
(
SELECT fc_station_mst.station_name,fc_station_mst.station_id,fc_station_mst.lat, fc_station_mst.longitude,fc_station_mst.state,
fc_station_param_dtl.fc_date,fc_station_param_dtl.param_value,fc_parameter_mst.param_name,fc_parameter_mst.param_unit,
6371*(2*atan2 (sqrt(sin(((3.14*(fc_station_mst.lat-23.07))/180)/2) *
sin(((3.14*(fc_station_mst.lat-23.07))/180)/2)+cos((3.14*fc_station_mst.lat)/180)*cos((3.14*23.07)/180)
* sin(((3.14*(fc_station_mst.longitude-72.71))/180)/2)*
sin(((3.14*(fc_station_mst.longitude-72.71))/180)/2)),(sqrt(1-(sin(((3.14*(fc_station_mst.lat-23.07))/180)/2)
*sin(((3.14*(fc_station_mst.lat-23.07))/180)/2) +cos((3.14*fc_station_mst.lat)/180)* cos((3.14*23.07)/180)*
sin(((3.14*(fc_station_mst.longitude-72.71))/180)/2)* sin(((3.14*(fc_station_mst.longitude-72.71))/180)/2)))))) as distance
FROM fc_station_mst, fc_station_param_dtl, fc_parameter_mst
where fc_station_param_dtl.param_id=fc_parameter_mst.param_id and
fc_station_mst.station_id=fc_station_param_dtl.station_id and fc_station_param_dtl.param_id in(1,3,5,9) and
fc_station_param_dtl.hourly_forecast='24' and fc_station_param_dtl.fc_date='22-JUL-2014'
) x
where distance <= 15 ;
答案 0 :(得分:0)
尝试使用和限制订单:
select *
from
(
SELECT fc_station_mst.station_name,fc_station_mst.station_id,fc_station_mst.lat, fc_station_mst.longitude,fc_station_mst.state,
fc_station_param_dtl.fc_date,fc_station_param_dtl.param_value,fc_parameter_mst.param_name,fc_parameter_mst.param_unit,
6371*(2*atan2 (sqrt(sin(((3.14*(fc_station_mst.lat-23.07))/180)/2) *
sin(((3.14*(fc_station_mst.lat-23.07))/180)/2)+cos((3.14*fc_station_mst.lat)/180)*cos((3.14*23.07)/180)
* sin(((3.14*(fc_station_mst.longitude-72.71))/180)/2)*
sin(((3.14*(fc_station_mst.longitude-72.71))/180)/2)),(sqrt(1-(sin(((3.14*(fc_station_mst.lat-23.07))/180)/2)
*sin(((3.14*(fc_station_mst.lat-23.07))/180)/2) +cos((3.14*fc_station_mst.lat)/180)* cos((3.14*23.07)/180)*
sin(((3.14*(fc_station_mst.longitude-72.71))/180)/2)* sin(((3.14*(fc_station_mst.longitude-72.71))/180)/2)))))) as distance
FROM fc_station_mst, fc_station_param_dtl, fc_parameter_mst
where fc_station_param_dtl.param_id=fc_parameter_mst.param_id and
fc_station_mst.station_id=fc_station_param_dtl.station_id and fc_station_param_dtl.param_id in(1,3,5,9) and
fc_station_param_dtl.hourly_forecast='24' and fc_station_param_dtl.fc_date='22-JUL-2014'
) x
where x.distance <= 15 order by x.distance asc limit 1;