Oracle SELECT - alias of one column as input for another

People I found similar, but not exact questions on this forum - forgive me if I did not do enough search for them. This is my question ... at Oracle

select ( t.value*2) as inst2, (inst2 * 3) as inst3 from table t; 

thinking behind, if f() = t.value*2 is an expensive call, then we don’t need to do this twice .. or is there an alternative query structure that I could use (I'm trying to achieve this in CTAS)

early.

+4
source share
2 answers

Another option:

 with cte as ( select t.value*2 as inst2 ) select cte.inst2, (cte.inst2*3) as inst3 from cte 

This is actually the same as the bluefeet answer, but I would find it easier to understand with with -syntax.

+2
source

If you want to use an alias in the second calculation, you will want to use a subquery:

 select inst2, (inst2 * 3) as inst3 from ( select t.value*2 as inst2 from table t ) 
+1
source

Source: https://habr.com/ru/post/1469010/


All Articles