问题
Is it possible to do something like select 1 as foo, foo+1 from dual
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
回答1:
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
来源:https://stackoverflow.com/questions/11315870/use-column-alias-in-select-statement-calculation-oracle-sql