使用 postgres 创建一个包含三个不同表的三列的视图

Create a view with three columns of three different tables using postgres

我的数据库 t1、t2 和 t2 中有三个表,它们具有类似的字段,如下所示: 我必须在 postgres 中创建一个包含三列的物化视图,其中包含我在三个表中的所有数据。

在这种情况下 t1.serial, t2.id, t3.serialno,应该是视图中名为 serial 的第一列; T1.type, t2.model, t3.typeof 应该是视图中名为 type 的第二列,t1.kind, t2.product and t3.ci_product 应该是视图中名为 kind 的第三列。我试过加入但没有用。任何的想法?提前致谢。

t1
------------------------
serial  type   kind
------------------------
qdds    cisco  switch
sjkal   ibm    router
dsafs   cisco  switch

t2:

t2
-----------------------
id      model  product
-----------------------
1223    ibm    switch
dsfsf22 ibm    switch
onakj   other  chassis

和 t3:

t3
-----------------------
serialno typeof  ci_product
-----------------------
sdfs     ibm     switch
sdfsssa  twitter other
231dsfs  other   other

看来你的意思是 UNION 运算符:

create materialized view as 
select t1.serial serial, t1.type type, t1.kind kind from t1
union
select t2.id, t2.model, t2.product from t2
union
select t3.serialno, t3.typeof, t3.ci_product from t3;