2011-11-17 59 views
0

我有這樣的SQL查詢:錯誤在距離SQL查詢

SELECT 
    *, 
    6371.04 * acos(cos(pi()/2 - radians(90 - `Tournament`.`latitude`)) * cos(pi()/2 - radians(90 - 37.226)) * cos(radians(`Tournament`.`longitude`) - radians(-93.4397)) + sin(pi()/2 - radians(90 - `Tournament`.`latitude`)) * sin(pi()/2 - radians(90 - 37.226))) AS `Tournament`.`dist` 
FROM `tournaments` AS `Tournament` 
WHERE 1 = 1 
ORDER BY `Tournament`.`dist` ASC 
LIMIT 5 

我想不出有什麼能可能是錯誤的這種說法。這是我得到的錯誤:

1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`dist` FROM `tournaments` AS `Tournament` WHERE 1 = 1 ORDER BY `Tournament`' at line 1 

任何人都可以指出我在正確的方向嗎?

+0

我試着用http://www.dpriver.com/pp/sqlformat.htm格式化您的查詢,但可悲的是有很多的問題。請檢查鏈接。 –

回答

1
AS `Tournament`.`dist` 

這可能是抱怨點。嘗試將它分配到dist

+0

有沒有辦法將它分配給表?如果我想從多個表中分配一個dist,該怎麼辦? – LordZardeck

+0

@LordZardeck,他指的是第一個「AS' Tournament'.'dist'」。在ORDER BY子句中沒問題。但它不允許作爲別名。 – mdahlman

+1

嘗試'tournament_dist'或'tournamentDist' :) –