Reuse column calculations
In my query I have a lot of columns that are a result of complicated calculations, some of the columns can be computed as a result of other columns.
My question is without creating a nested SQL can I refer to column alias so that I don't have to specify the same calculation twice.
Below is a simplified example of what I am trying to do where the column alias num2 and num21 are simplified examples of the calculations
I need to perform. The first query below works fine but I have to specify my calculation (num *2) twice.
select num * 2 num2, (num *2) + 1 num21 from
(select 2 num from dual)
I would like to somehow refer the num2 alias in my second column as shown below. (so that (num * 2) is speicified only once) But I get a SQL error saying the num2 idenitifer is not valid.
select num * 2 num2, num2 + 1 from
(select 2 num from dual)