我和#1895500有同样的问题, 但使用 PostgreSQL 而不是 MySQL。
如何定义具有计算字段的 View ,例如:
(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
关于sql - PostgreSQL View : Referencing one calculated field in another calculated field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2385791/