douzong3599 2014-01-09 11:42
浏览 26
已采纳

mysql查询中的未知列错误

I am calculating radius between loading and delivery points.

I have made a query for it but its giving me error :

unknown column distance1

Here is the query:

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  
  • 写回答

1条回答 默认 最新

  • dongxu1875 2014-01-09 11:50
    关注

    use below query - make use of having clause rather than 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 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?