Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Column Alias In Select Statement Calculation Oracle SQL [duplicate]

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

like image 289
Brandon Kreisel Avatar asked May 26 '26 13:05

Brandon Kreisel


1 Answers

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
like image 122
Lamak Avatar answered May 28 '26 04:05

Lamak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!