mysql - 无法让查询工作

时间:2016-03-23 09:40:02

标签: mysql

我不能为我的生活看到这里出了什么问题。它最有可能是愚蠢的,但我目前对此视而不见!我有一个问题:

SELECT 
Links.Title,
(6371 * acos( cos( radians(43.4347229) ) * cos( radians( Links.Latitude ) ) * cos( radians( Links.Longitude ) - radians(6.737222195) ) + sin( radians(43.4347229) ) * sin( radians( Links.Latitude ) ) ) AS distance 
FROM CatLinks,Links WHERE CatLinks.LinkID = Links.ID AND (Links.ID IN (16650,17190,153344) AND Links.isValidated = 'Yes' AND Links.PropertyType IN (1,2,3) AND Links.priceSort <= '9999' AND Links.PropertyType IN (1,2,3) AND Links.priceSort < '9999') ORDER BY distance LIMIT 0,50

..我收到错误:

  

错误:无法执行查询:无法执行查询:'SELECT   Links.Title,(6371 * acos(cos(弧度(43.4347229))* cos(弧度(   Links.Latitude))* cos(弧度(Links.Longitude) -   弧度(6.737222195))+ sin(弧度(43.4347229))* sin(弧度(   Links.Latitude)))AS FROM FROM CatLinks,Links WHERE   CatLinks.LinkID = Links.ID AND(Links.ID IN(16650,17190,153344))   ORDER BY distance LIMIT 0,50':您的SQL语法有错误;   检查与您的MySQL服务器版本对应的手册   在'AS距离FROM CatLinks,链接WHERE附近使用正确的语法   CatLinks.LinkID ='第3行

即使将其修改为更简单的查询,也不想工作:

SELECT 
    glinks_Links.Title,
    (6371 * acos( cos( radians(43.4347229) ) * cos( radians( glinks_Links.Latitude ) ) * cos( radians( glinks_Links.Longitude ) - radians(6.737222195) ) + sin( radians(43.4347229) ) * sin( radians( glinks_Links.Latitude ) ) ) AS distance 
    FROM glinks_CatLinks,glinks_Links ORDER BY distance LIMIT 0,50

我整个上午一直都在讨论这个问题,所以任何建议都会非常感激!

1 个答案:

答案 0 :(得分:3)

您忘记关闭括号(sin( radians( Links.Latitude ) ) ) )附近)。试试这个

SELECT
    Links.Title,
    (
        6371 * acos(
            cos(radians(43.4347229)) * cos(radians(Links.Latitude)) * cos(
                radians(Links.Longitude) - radians(6.737222195)
            ) + sin(radians(43.4347229)) * sin(radians(Links.Latitude))
        )
    ) AS distance
FROM
    CatLinks,
    Links
WHERE
    CatLinks.LinkID = Links.ID
AND (
    Links.ID IN (16650, 17190, 153344)
    AND Links.isValidated = 'Yes'
    AND Links.PropertyType IN (1, 2, 3)
    AND Links.priceSort <= '9999'
    AND Links.PropertyType IN (1, 2, 3)
    AND Links.priceSort < '9999'
)
ORDER BY
    distance
LIMIT 0,50