本文介绍了PostgreSQL视图:在另一个计算字段中引用一个计算字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我与#1895500 ,但使用PostgreSQL而不是MySQL。
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...?
推荐答案根据formla的沉重程度,您可以使用子查询:
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或重写计算:
select mycol * 2, mycol * 2 * 2 from table更多推荐
PostgreSQL视图:在另一个计算字段中引用一个计算字段
发布评论