我和#1895500有同样的问题,但是PostgreSQL不是MySQL。
如何定义具有计算字段的视图,例如:

 (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

10-07 19:13
查看更多