簡體   English   中英

如何在php mysql查詢中添加where條件

[英]how to add where condition in php mysql query

我使用下面的查詢獲取最近的地方。而如果我加入其中錯誤出現在哪里條件無效。

SELECT
    attName,
    description,
    rating,
    COMMENT,
    latitude,
    langtitude,
    openingTime,
    closingTime,
    (
        (
            ACOS(
                SIN(".$lat." * PI() / 180) * SIN(latitude * PI() / 180) + COS(".$lat." * PI() / 180) * COS(latitude * PI() / 180) * COS(
                    (".$lang." - langtitude) * PI() / 180
                )
            ) * 180 / PI()
        ) * 60 * 1.1515
    ) AS distance
FROM
    attraction
HAVING
    distance < 31
ORDER BY
    distance

如果我加入where條件錯誤come.please幫助我如何添加這些條件上面的查詢。

嘗試使用WHERE條件替換HAVING子句:

SELECT attName, description, rating, 
                COMMENT , latitude, langtitude, openingTime, closingTime,(
                (
                ACOS( SIN(  ".$lat." * PI( ) /180 ) * SIN( latitude * PI( ) /180 ) + COS(  ".$lat." * PI( ) /180 ) * COS( latitude * PI( ) /180 ) * COS( (
                 ".$lang." - langtitude
                ) * PI( ) /180 ) ) *180 / PI( )
                ) *60 * 1.1515
                ) AS distance
                FROM attraction

                WHERE distance < 31

                ORDER BY distance 

然后添加附加條件為AND this = that

HAVING子句通常與GROUP BY一起使用 - 您沒有。

SELECT ... FROM ... WHERE ... GROUP BY ... HAVING ... ORDER BY ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM