2
我有與#1895500相同的問題,但使用PostgreSQL而不是MySQL。PostgreSQL視圖:引用另一個計算字段中的一個計算字段
我如何定義,有一個計算的字段,例如一個觀點:
(mytable.col1 * 2) AS times_two
...並打造了基於第一彼此計算字段:
(times_two * 2) AS times_four
.. 。?
我有與#1895500相同的問題,但使用PostgreSQL而不是MySQL。PostgreSQL視圖:引用另一個計算字段中的一個計算字段
我如何定義,有一個計算的字段,例如一個觀點:
(mytable.col1 * 2) AS times_two
...並打造了基於第一彼此計算字段:
(times_two * 2) AS times_four
.. 。?
根據formla是多麼沉重,你可以使用子查詢:
select inner.*, times_two * 2 from
(select mycol * 2 as times_two from table) sub
或重寫計算:
select mycol * 2, mycol * 2 * 2 from table
此語句
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 ;