Domanda

Ho la stessa domanda come # 1895500 , ma con PostgreSQL non MySQL.

Come posso definire una vista che ha un campo calcolato, ad esempio:

 (mytable.col1 * 2) AS times_two

... e creare un altro campo calcolato che si basa sul primo:

 (times_two * 2) AS times_four

...

È stato utile?

Soluzione

A seconda di come pesante il formla è, si potrebbe utilizzare una sottoquery:

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

O riscrivere il calcolo:

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

Altri suggerimenti

  

Utilizzare questa istruzione

 
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 ; 


Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top