【问题标题】:Is there a way to rename output abreviated columns in a CTE query?有没有办法重命名 CTE 查询中的输出缩写列?
【发布时间】:2020-12-02 17:44:24
【问题描述】:

我需要重命名 CTE 查询的输出列。我想这可以通过命令AS 来完成,但我不知道该放在哪里。

例如

with
   table1 as (
   select 
      atribute1 as a1
      atribute2 as a2
   from table2 
   ),         
   table3
   select
      atribute3 as a3 
   from table4
)
select
   table1.a1
   table1.a2
   table3.a3
   from table1
   join table 3 on table3.a3=table1.a1
;

这会给我一个表的输出,其列名如a1(第一列)、a2(第二列)、a3(第三列)。我想将它们重命名为a1、a2 和a3。

谢谢!

【问题讨论】:

    标签: sql postgresql inner-join common-table-expression


    【解决方案1】:

    您似乎想为最终结果集中的列设置别名。你可以这样做:

    with 
        table1 as (...),
        table3 as (...)
    select
        t1.a1 as first_column
        t1.a2 as second_column
        t3.a3 as third_column
    from table1 t1
    join table3 t3 on t3.a3 = t1.a1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-08
      • 2018-09-29
      • 1970-01-01
      • 1970-01-01
      • 2017-02-24
      • 2011-03-26
      • 2017-12-08
      相关资源
      最近更新 更多