在 Select 语句计算中使用列别名 Oracle SQL

2021-12-30 00:00:00 sql alias oracle11g oracle

是否可以做类似select 1 as foo, foo+1 from dual

这将在第 1 行返回 ERROR: ORA-00904: "FOO": invalid identifier

This returns ERROR at line 1: ORA-00904: "FOO": invalid identifier

我有一个组成一列的冗长计算,我希望能够轻松地使用该值在差异列中进行计算

I have a lengthy calculation that composes a column and I would like to be able to easily use that value for calculation in a difference column

推荐答案

不能直接使用别名.一种方法是使用派生表:

You can't use an alias directly. One way is to use a derived table:

SELECT foo, foo+1
FROM (SELECT 1 AS foo FROM dual) AS T

相关文章