MySQL查询失败,因为列表中的列名
我有一个MySQL查询,可以完美地工作,没有具有
子句,但是当我使用该子句时,我会遇到错误,我认为这与我使用该子句进行比较有关用我在选择中声明的列名称。
查询:
SELECT
DISTINCT p.ID,
p.post_title,
practice_latitude.meta_value as locLat,
practice_longitude.meta_value as locLong,
(
'3959' * acos(
cos(radians('39.40517956963392')) * cos(radians(practice_latitude.meta_value)) * cos(
radians(practice_longitude.meta_value) - radians('-118.99713149999997')
) + sin(radians('39.40517956963392')) * sin(radians(practice_latitude.meta_value))
)
) AS distance
FROM
wp_posts p
INNER JOIN wp_postmeta practice_latitude ON p.ID = practice_latitude.post_id
INNER JOIN wp_postmeta practice_longitude ON p.ID = practice_longitude.post_id
WHERE
p.post_type = 'awpcp_listing'
AND p.post_status = 'publish'
AND practice_latitude.meta_key = '_awpcp_extra_field[36]'
AND practice_longitude.meta_key = '_awpcp_extra_field[37]'
HAVING
distance < 500
group by
practice_latitude.meta_value,
practice_longitude.meta_value;
似乎在选择中声明的“距离”列是问题。我该如何纠正以应用适当的有子句 e,由于查询否则可以很好地工作?
I have a mysql query that works perfectly without the HAVING
clause, but when I use that clause I get an error and I think it has to do with the fact that I'm using the clause for a comparison with a column name that I declare in my select.
The Query:
SELECT
DISTINCT p.ID,
p.post_title,
practice_latitude.meta_value as locLat,
practice_longitude.meta_value as locLong,
(
'3959' * acos(
cos(radians('39.40517956963392')) * cos(radians(practice_latitude.meta_value)) * cos(
radians(practice_longitude.meta_value) - radians('-118.99713149999997')
) + sin(radians('39.40517956963392')) * sin(radians(practice_latitude.meta_value))
)
) AS distance
FROM
wp_posts p
INNER JOIN wp_postmeta practice_latitude ON p.ID = practice_latitude.post_id
INNER JOIN wp_postmeta practice_longitude ON p.ID = practice_longitude.post_id
WHERE
p.post_type = 'awpcp_listing'
AND p.post_status = 'publish'
AND practice_latitude.meta_key = '_awpcp_extra_field[36]'
AND practice_longitude.meta_key = '_awpcp_extra_field[37]'
HAVING
distance < 500
group by
practice_latitude.meta_value,
practice_longitude.meta_value;
It seems like the 'distance' column being declared in the select is the issue though. How can I correct that to apply the appropriate HAVING clause
e, since the query otherwise works perfectly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论