Subject Computed column reuse in VIEW
Author Adomas Urbanavicius
Hi,

Any suggestions how to reuse computed column in view ?
Idea :
If we have komplex calculated column, and later it acts as argument for
other columns, it would be nice to reuse column in later selections:
Example:
Lets say we have select customer,profit,profit_perc,forecasted_profit
from tb_customers.
profit - is komplex subselect . (select profit from my_komplex_subselect)
profit_perc = profit/<...>,
forecasted_profit = profit * <...>/ <...>.

So instead of writing
create view v1 (....) as
select
customer,
(select profit from my_komplex_subselect),
(select profit from my_komplex_subselect)/<...>,
(select profit from my_komplex_subselect)* <...>/<....>
from tb_customers
we could write
create view v1 (....) as
select
customer,
(select profit from my_komplex_subselect) AS profit_alias,
profit_alias/<...>,
profit_alias* <...>/<....>
from tb_customers


--

Best Regards,
Adomas Urbanavicius