php - mysql 查询中出现未知列错误

标签 php 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  

最佳答案

使用下面的查询 - 使用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 

关于php - mysql 查询中出现未知列错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21019222/

相关文章:

php - MYSQL 如何确保行不会多次更新?

javascript - 销售点系统

php - 带有版本号的文件名...这是个好主意吗?

php - 1060 SQL 查询错误

php - 当前页面上产品的分页计数范围

mysql - Yum 将 Percona 从 5.6.25-rel73.1 更新到 5.6.26-rel74.0 导致服务器无法启动

php - MySQL 查询正在创建重复行

php - VI编辑器_将文件夹从Windows移动到Web服务器

php - ob_start 和 ob_gzhandler 函数到底做了什么

php - 从 MySQL 表中获取多行值