Use Column Alias In Select Statement Calculation Oracle SQL

白昼怎懂夜的黑 提交于 2019-12-23 18:37:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!