PostgreSQL Views: Referencing one calculated field in another calculated field
calculated-columns, postgresql, sql, sql-view
Solution
Depending on how heavy the formla is, you could use a subquery:
select inner.*, times_two * 2 from
(select mycol * 2 as times_two from table) sub
Or rewrite the computation:
select mycol * 2, mycol * 2 * 2 from table
Problem
I have the same question as #1895500, but with PostgreSQL not MySQL. How can I define a view that has a calculated field, for example: ``` (mytable.col1 * 2) AS times_two ``` ... and create another calculated field that's based on the first one: ``` (times_two * 2) AS times_four ``` ...?