我有一个这样的SQL语句:

SELECT
(111.045 * DEGREES(ACOS(COS(RADIANS({$lat}))
* COS(RADIANS(lat))
* COS(RADIANS({$lon}) - RADIANS(lon)) + SIN(RADIANS({$lat}))
* SIN(RADIANS(lat))))) AS distance,
(`f1` + `f2` + `f5` + `f6`) AS sum
FROM `shops`
WHERE distance <= 25


其中第一部分返回一定距离内的商店,第二部分返回同一表的同一行中给定字段的总和。

这两部分分别工作,但结合使用时不会返回结果。

请告诉我我做错了什么?

最佳答案

不要在哪里使用别名

SELECT
(111.045 * DEGREES(ACOS(COS(RADIANS({$lat}))
* COS(RADIANS(lat))
* COS(RADIANS({$lon}) - RADIANS(lon)) + SIN(RADIANS({$lat}))
* SIN(RADIANS(lat))))) AS distance,
(f1 + f2 + f5 + f6) AS sum
FROM shops
WHERE   (111.045 * DEGREES(ACOS(COS(RADIANS({$lat}))
* COS(RADIANS(lat))
* COS(RADIANS({$lon}) - RADIANS(lon)) + SIN(RADIANS({$lat}))
* SIN(RADIANS(lat))))) <= 25

关于mysql - 从单个表合并两个MySQL SELECT查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39085644/

10-13 02:05