有没有办法在函数内部为 "table.column" 类型的查询设置别名?
Is there a way to alias a query of the type "table.column" inside a function?
我创建了一个 CTE,CTE 的第二部分包含一个 select 和一个 st_contains。在这一个中,我有两列具有相同名称的不同表。我想为这个 'table.column' 组合之一起别名,因为当我在 CTE 末尾执行 selection 输出错误时;列引用“ ”不明确。
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
;
我希望我能很好地解释问题。
谢谢!
在您的 table2 CTE 中为表 3 和表 4 列添加别名以解决歧义。
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
;
我创建了一个 CTE,CTE 的第二部分包含一个 select 和一个 st_contains。在这一个中,我有两列具有相同名称的不同表。我想为这个 'table.column' 组合之一起别名,因为当我在 CTE 末尾执行 selection 输出错误时;列引用“ ”不明确。
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
;
我希望我能很好地解释问题。 谢谢!
在您的 table2 CTE 中为表 3 和表 4 列添加别名以解决歧义。
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
;