Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.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
来自其他表的Postgres/SQL行标题_Sql_Postgresql - Fatal编程技术网

来自其他表的Postgres/SQL行标题

来自其他表的Postgres/SQL行标题,sql,postgresql,Sql,Postgresql,我有一个postgres数据库,其中有两个表,我想合并成一个表 第一个表如下所示(例如): 二是: ID | Type 236 | Headername1 326 | Headername2 337 | Headername3 是否存在返回第一个表但标题名称正确的查询: Datetime | Headername1 | Headername2 | Headername3 timestamp| value | value | value timestamp| v

我有一个postgres数据库,其中有两个表,我想合并成一个表

第一个表如下所示(例如):

二是:

ID   | Type
236  | Headername1
326  | Headername2
337  | Headername3
是否存在返回第一个表但标题名称正确的查询:

Datetime | Headername1 | Headername2 | Headername3
timestamp| value       | value       | value
timestamp| value       | value       | value
timestamp| value       | value       | value

除非构建动态查询,否则无法执行此操作

首先需要获取用作别名的名称,然后构建将此别名分配给相应列的查询

SO中有一些样本:

    • 这样做

        SELECT Datetime,
               Obj236 as Headername1,
               Obj326 as Headername2,
               Obj337 as Headername3
        FROM    dbname;
      
        SELECT Datetime,
               Obj236 as Headername1,
               Obj326 as Headername2,
               Obj337 as Headername3
        FROM    dbname;