gpt4 book ai didi

mysql - #1054 - MySQL 中 'proximite' 中的未知列 'where clause'

转载 作者:行者123 更新时间:2023-11-29 08:06:55 25 4
gpt4 key购买 nike

运行下面的查询时,我最终在 PHPMyAdmin 中遇到 MYSQL 错误:

1054 - “where 子句”中存在未知列“proximite”

我正在使用 mysql 5.6 和 phpMyAdmin,Proximite 出现错误,请我需要帮助例如,查找距离巴黎埃菲尔铁塔最近的 10 家餐厅(纬度:48.858205,经度:2.294359)且距离小于 1 公里。该数据库包含一个表“restaurants”。该表包含与餐厅的纬度和经度相对应的“lat”和“lng”等字段这是我的尝试:

SELECT *, get_distance_metres('48.858205', '2.294359', lat, lng) 
AS proximite
FROM restaurants
WHERE proximite < 1000 ORDER BY proximite ASC
LIMIT 10

最佳答案

您不能在相同查询的WHERE子句中使用该别名。

试试这个:

SELECT *, get_distance_metres('48.858205', '2.294359', lat, lng) 
AS proximite
FROM restaurants
WHERE get_distance_metres('48.858205', '2.294359', lat, lng) < 1000
ORDER BY proximite ASC
LIMIT 10

文档:

Standard SQL disallows references to column aliases in a WHERE clause. This restriction is imposed because when the WHERE clause is evaluated, the column value may not yet have been determined.

<强> Source

关于mysql - #1054 - MySQL 中 'proximite' 中的未知列 'where clause',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22538579/

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