我正在计算装货点和交货点之间的半径。
我已经对它进行了查询,但它给了我错误:
未知列距离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
答案 0 :(得分:1)
使用以下查询 - 使用having子句而不是where -
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 having distance1 <= LocationRadiusStart AND distance2 <= LocationRadiusEnd OR distance3 <= LocationRadiusEnd AND distance3 <= LocationRadiusStart