如何...或可以我在同一个select-clause和where-clause中使用字段别名a.k.a. field as val
?
select
a.LONG_NAME_I_CANT_REMEMBER as val1,
a.NAME_I_DONT_WANT_2_REMEMBER as val2,
val1-val2 as diff
from
random_table a
where
(val1 > 12)
没有内联视图/内联查询,而不是关于表别名。
答案 0 :(得分:3)
您无法在SELECT
子句的WHERE
子句中使用您定义的别名。逻辑上,在确定要显示哪些列(WHERE
列表)之前确定要返回哪些行(应用SELECT
子句),以便在处理WHERE
子句时,别名为&#39 ; t存在。
当然,您可以重构查询,以便在内联视图中选择和别名数据,然后在该视图外部应用WHERE
子句。像
select a.*,
val1-val2 as diff
from (select a.LONG_NAME_I_CANT_REMEMBER as val1,
a.NAME_I_DONT_WANT_2_REMEMBER as val2,
from random_table a) a
where (val1 > 12)