2
我正在搜索stackoverflow並得到了我的問題的答案,但是當我試圖用我的代碼實現它時,我得到了奇怪的錯誤。用於大圓計算的SQL錯誤
這裏是代碼:
SELECT `zip_code`, (6371 * acos(cos(radians($latitude)) * cos(radians(`lat`)) * cos(radians(`long`) - radians($longitude)) + sin(radians($latitude)) * sin(radians(`lat`)))) AS `distance`
FROM `places`
HAVING `distance` < $within
ORDER BY `distance` ASC
LIMIT 10;
我得到以下錯誤:
Incorrect parameter count in the call to native function 'radians'
我使用MySQL的版本44年1月5日
是否有可能在字段中有NULLS。我認爲傳遞給該函數的空值可能會返回此錯誤 – Sparky 2011-12-25 18:46:21
這是從shell腳本啓動的嗎?給定的值是「緯度」還是「經度」? – 2011-12-25 19:09:36
是的,它們是給定值,並且沒有NULL值 – Grigor 2011-12-25 19:17:39