PostgreSQL视图:在另一个计算字段中引用一个计算字段

编程入门 行业动态 更新时间:2024-10-11 17:26:55
本文介绍了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视图:在另一个计算字段中引用一个计算字段

本文发布于:2023-10-23 14:16:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1521064.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   视图   PostgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!