0
我有一個查詢,它返回距離一組XY座標最遠的sighting_id。即時通訊嘗試在XY座標上創建基於函數的索引以加快查詢速度,iv瞭解如何爲包含字符串的字段構建一個,但不確定如何構建xy座標。基於函數的索引XY座標
的架構目擊(sighting_id(PK),spotter_id,bird_id,緯度,經度,年月日,描述)
WITH params as (SELECT -28 as lat, 151 as lon
FROM dual)
SELECT sighting_id, sqrt(power(lat - latitude, 2) + power(lon - longitude, 2))
AS distance FROM sightings CROSS JOIN params
WHERE sqrt(power(lat - latitude, 2) + power(lon - longitude, 2)) =
(SELECT MAX(sqrt(power(lat - latitude, 2) + power(lon - longitude, 2)))
FROM sightings CROSS JOIN params);