Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用postgres创建包含三个不同表的三列的视图_Sql_Postgresql_Postgresql 9.6 - Fatal编程技术网

Sql 使用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、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
------------------------
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