gpt4 book ai didi

mysql - 组合来自单个表的两个 MySQL SELECT 查询

转载 作者:行者123 更新时间:2023-11-29 20:30:46 25 4
gpt4 key购买 nike

我有这样的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com