我正在計算加載點和投遞點之間的半徑。MySQL查詢中的未知列錯誤
我已經做了查詢,但它給我的錯誤:
未知列距離1
下面是該查詢:
SELECT ((Acos(Sin('49.4634' * Pi()/180) * Sin(
`locationlatitudestart` * Pi()/180)
+
Cos(
'49.4634' * Pi()/180) * Cos(
`locationlatitudestart` * Pi()
/
180) * Cos((
'3.54404' - `locationlongitudestart`) * Pi()/
180)) *
180/Pi()) * 60 * 1.1515) AS distance1,
((Acos(Sin('48.8637' * Pi()/180) * Sin(
`locationlatitudeend` * Pi()/180) +
Cos
(
'48.8637' * Pi()/180) * Cos(
`locationlatitudeend` * Pi()/180) *
Cos
((
'2.36109' - `locationlongitudeend`) * Pi()/180)) *
180/Pi
()
) * 60 * 1.1515) AS distance2,
((Acos(Sin('49.4634' * Pi()/180) * Sin(
`locationlatitudeend` * Pi()/180) +
Cos
(
'49.4634' * Pi()/180) * Cos(
`locationlatitudeend` * Pi()/180) *
Cos
((
'3.54404' - `locationlongitudeend`) * Pi()/180)) *
180/Pi
()
) * 60 * 1.1515) AS distance3,
((Acos(Sin('48.8637' * Pi()/180) * Sin(
`locationlatitudestart` * Pi()/180)
+
Cos(
'48.8637' * Pi()/180) * Cos(`locationlatitudestart` * Pi()
/180)
*
Cos((
'2.36109' - `locationlongitudestart`) * Pi()/180)) *
180/
Pi
()) * 60 * 1.1515) AS distance4
FROM instant_quotes
WHERE distance1 <= locationradiusstart
AND distance2 <= locationradiusend
OR distance3 <= locationradiusend
AND distance3 <= locationradiusstart
感謝您的縮進我的代碼 –
You ca不要以這種方式在WHERE中使用列別名。你可以使用HAVING或者子查詢,或者再次引用整個第一位,或者(更好的想法)構造一個計算距離的函數。 – Strawberry
爲什麼你不在查詢前進行計算?或使用存儲過程? – yoavmatchulsky