【问题标题】:Refer to a column name alias in the WHERE clause [duplicate]在 WHERE 子句中引用列名别名 [重复]
【发布时间】:2015-06-16 12:34:49
【问题描述】:

我已经在 postgres sql 中用列别名写下了这个查询,它工作正常:

select email as e from users 

它在e 列别名下显示我的结果,但是当我使用e 触发where 条件时,它会显示此错误:

select email as e from users where e = 'jaskaransingh@demo.com'

错误:“e”列不存在

为什么会这样?如何在 where 条件下使用别名?

【问题讨论】:

    标签: sql postgresql alias


    【解决方案1】:

    whereselect 之前进行评估,因此您不能在where 子句中使用在select 中声明的别名。

    【讨论】:

    • 这是正确的,但让我很难过。这有充分的理由吗?能够在 where 子句中引用别名会非常有用。
    猜你喜欢
    • 2012-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-26
    相关资源
    最近更新 更多