I want to use the result from subquery as the column name of another query since the data changes column all the time and the subquery will decide which column the current forcast data stored. My example:
forcast_0 * 0.9 as finalforcast
forcast_0 * 0.8 as newforcast
but the forcast_0 column is the result (fore_column_name) of the subquery, the result may change to forcast_1 or forcast2
Also, the forcast column will be used multiple times in the first query. how could I implement this?
Best How To :
Use your sub query as an inline table. Something like....
decode(fore_column_name, 'foo', 1, 2) * 0.9 as finalforcast,
decode(fore_column_name, 'foo', 1, 2) * 0.8 as newforcast
I'm assuming here that the value from the sub-query will be the same for each row - so a quick cross-join will suffice. If the value will vary depending on the values in each row of the
sales_data table, then some other type of join would be more appropriate.
Quick link to decode - in case you aren't familiar with it.