2014-01-09 115 views
0

我正在計算加載點和投遞點之間的半徑。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 
+0

感謝您的縮進我的代碼 –

+1

You ca不要以這種方式在WHERE中使用列別名。你可以使用HAVING或者子查詢,或者再次引用整個第一位,或者(更好的想法)構造一個計算距離的函數。 – Strawberry

+1

爲什麼你不在查詢前進行計算?或使用存儲過程? – yoavmatchulsky

回答

1

使用下面的查詢 - 使having子句而使用比哪裏 -

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 
+0

好吧,現在它說Unknown列LocationRadiusStart'在'條款' –

+0

哦,它的固定。謝謝哥們。沒有人試圖友好 –

+0

感謝您的upvote和接受。 – Abhishek