当我尝试为子查询提供别名然后在 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/