Sql 使用postgres创建包含三个不同表的三列的视图
我的数据库t1、t2和t2中有三个表,具有类似的字段,如下所示: 我必须在postgres中创建一个具有三列的物化视图,所有数据都在这三个表中 在这种情况下,Sql 使用postgres创建包含三个不同表的三列的视图,sql,postgresql,postgresql-9.6,Sql,Postgresql,Postgresql 9.6,我的数据库t1、t2和t2中有三个表,具有类似的字段,如下所示: 我必须在postgres中创建一个具有三列的物化视图,所有数据都在这三个表中 在这种情况下,t1.serial、t2.id、t3.serialno,应该是视图中名为serial的第一列T1.type,t2.model,t3.typeof应该是视图中名为type的第二列,T1.kind,t2.product和t3.ciu product应该是视图中名为kind的第三列。我尝试使用联接,但不起作用。有什么想法吗?提前谢谢 t1 ---
t1.serial、t2.id、t3.serialno
,应该是视图中名为serial
的第一列T1.type,t2.model,t3.typeof
应该是视图中名为type
的第二列,T1.kind,t2.product和t3.ciu product
应该是视图中名为kind
的第三列。我尝试使用联接,但不起作用。有什么想法吗?提前谢谢
t1
------------------------
serial type kind
------------------------
qdds cisco switch
sjkal ibm router
dsafs cisco switch
t2:
和t3:
t3
-----------------------
serialno typeof ci_product
-----------------------
sdfs ibm switch
sdfsssa twitter other
231dsfs other other
您的意思似乎是联合运营者:
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;
您的意思似乎是联合运营者:
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;
我想你需要告诉我们这些表格是如何关联的。我们只能猜测您的数据模型。@TimBiegeleisen此表不相关,只是serial、id、serialno与type、model和typof以及kind、product和ci_product相同。如果您想从这三个表中获得一个视图,那么您必须告诉我们如何连接它们。这对你有意义吗?@TimBiegeleisen这三张桌子没有连接。我只是希望所有表记录在同一个表/视图(所有记录都不同)的同一个名称列下。我不知道这是可能的。我对sql有点陌生。我认为您需要告诉我们这些表是如何关联的。我们只能猜测您的数据模型。@TimBiegeleisen此表不相关,只是serial、id、serialno与type、model和typof以及kind、product和ci_product相同。如果您想从这三个表中获得一个视图,那么您必须告诉我们如何连接它们。这对你有意义吗?@TimBiegeleisen这三张桌子没有连接。我只是希望所有表记录在同一个表/视图(所有记录都不同)的同一个名称列下。我不知道这是可能的。我对sql有点陌生。您可能需要这里的
UNION ALL
。您可能需要这里的UNION ALL
。