gpt4 book ai didi

mysql - 为什么我在 'where clause' 中使用 MySQL 的子查询别名得到未知列?

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

当我尝试为子查询提供别名然后在 Where 子句中引用它时,我收到一条错误消息:“where 子句”中的未知列“point_status”

SELECT goals.id, goals.status, 
ifnull((SELECT point_status FROM pts WHERE point_id = ?), goals.status) as point_status
FROM goals
WHERE goals.name = ? AND point_status > 1

我不明白为什么它不允许我使用这个别名。是否可以通过不修改查询的功能以某种方式在 where 子句中使用该别名?

最佳答案

It is not allowable to refer to a column alias in a WHERE clause, because the column value might not yet be determined when the WHERE clause is executed.

这意味着您不能在 where 子句中使用别名。

尝试将 where 替换为 having

关于mysql - 为什么我在 'where clause' 中使用 MySQL 的子查询别名得到未知列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27989866/

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