有没有一种方法可以重命名CTE查询中的输出省略列



我需要重命名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(第三列(。我想将它们重命名为a1a2a3

谢谢!

您似乎想要对最终结果集中的列进行别名。你可以做:

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

最新更新