Question

J'ai la même question que # 1895500 , mais avec PostgreSQL pas MySQL.

Comment puis-je définir une vue qui a un champ calculé, par exemple:

 (mytable.col1 * 2) AS times_two

... et créer un autre champ calculé qui est basé sur la première:

 (times_two * 2) AS times_four

...

Était-ce utile?

La solution

En fonction de la lourde formla est, vous pouvez utiliser une sous-requête:

select inner.*, times_two * 2 from
(select mycol * 2 as times_two from table) sub

Ou réécrire le calcul:

select mycol * 2, mycol * 2 * 2 from table

Autres conseils

  

Cette instruction

 
CREATE  VIEW  view_name as  SELECT  column_name*2 as new_col1 , column_name*4 as new_col2  from table_name ; 

select * from view_name ; 

If you want use this view column values. use following things 

create view new_viwe as select new_col1*2 as final_column from view_name ; 

select * from new_view ; 


Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top