有没有办法在函数中为"table.column"类型的查询设置别名?



我创建了一个CTE,CTE的第二部分包含一个带有st_contains的select。在这个例子中,我有两列不同的表,它们的名称相同。当我在CTE输出错误的末尾进行选择时,我想别名这个"table.column"组合中的一个;列引用"不明确。

with
table1 as (
...
),         
table2 as (
select*
from table3, table4
where st_contains (table3.atribute1, table4.atribute1)
)
select
table1.atribute1      
table2.atribute1      #here i need somethig like table2.table3.atribute1
from table1
join table2 on table1.atribute2=table2.atribute2
;

我希望我能很好地解释这个问题。谢谢

在table2CTE中对table3和table4列进行别名以解决歧义。

with
table1 as (
...
),         
table2 as (
select table3.attribute1 table3atrr1, table4.attribute1 table4attr1
from table3, table4
where st_contains (table3.atribute1, table4.atribute1)
)
select
table1.atribute1      
table2.table3atrr1 -- use the aliased column name
from table1
join table2 on table1.atribute2=table2.atribute2
;

相关内容

最新更新