Subject | Computed column reuse in VIEW |
---|---|
Author | Adomas Urbanavicius |
Post date | 2006-02-27T08:36:28Z |
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
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