gpt4 book ai didi

具有两列的 MySQL 子查询 - 如何隐藏第二列?

转载 作者:行者123 更新时间:2023-11-29 02:49:00 25 4
gpt4 key购买 nike

即使我已经对此进行了所有搜索和阅读,但我仍然很难思考如何做到这一点!

我有一个查询,我正在使用它来尝试从数据库中提取所有用户,这些用户的邮政编码在给定的小数坐标的特定距离内。这是我正在运行的查询:

select distinct watch_list.username, enabled 
from watch_list, registered_users
where watch_list.username = registered_users.username AND watch_list.watchzip = (
SELECT zip,
( 3959 * acos( cos( radians('29.7632800') ) *
cos( radians( lat ) ) *
cos( radians( lng ) -
radians('-95.3632700') ) +
sin( radians('29.7632800') ) *
sin( radians( lat ) ) ) )
AS distance from zip
HAVING distance <= '10');

我返回的错误是预期的,因为我的子查询返回两列:

MySQL said: Documentation
#1241 - Operand should contain 1 column(s)

在子查询不返回两列的情况下,如何执行此操作并过滤距离?

附言为了完成和提供信息,“邮政编码”表包含美国所有邮政编码及其小数坐标的列表。

最佳答案

只需将操作移出列列表即可:

select distinct watch_list.username, enabled
from watch_list, registered_users
where watch_list.username = registered_users.username
AND watch_list.watchzip = (
SELECT zip
from zip
WHERE ( 3959 * acos( cos( radians('29.7632800') ) *
cos( radians( lat ) ) *
cos( radians( lng ) -
radians('-95.3632700') ) +
sin( radians('29.7632800') ) *
sin( radians( lat ) ) ) ) <= '10');

编辑:正如 P.Salmon 提到的,您可能还想将 AND watch_list.watchzip = 更改为 AND watch_list.watchzip IN

关于具有两列的 MySQL 子查询 - 如何隐藏第二列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38078426/

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