我是 MS SQL-Server 的新手。我对此有疑问。
我有一个查询:
with by_segment as (
SELECT
Road.Road_ID,
GEOMETRY::STGeomFromText(Track.Track.STAsText(),4326) as the_geom,
row_number() over (partition by road_id order by Segment_Id) as [rn],
count(*) over (partition by road_id) as [c]
FROM dbo.Road
LEFT JOIN Segment_ID ON Road.Road_ID = Segment_ID.Road_ID
LEFT JOIN Track ON Segment_ID.Segment_ID = Track.Segment_ID
),
roads_by_segment as (
select
road_id,
the_geom,
[rn],
[c]
from by_segment
where [rn] = 1
union all
select
[a].road_id,
[a].the_geom.STUnion([b].the_geom),
[b].[rn],
[b].[c]
from by_segment as [a]
inner join roads_by_segment as [b]
on [a].segment_id = b.[segment_id]
and [a].[rn] = [b].[rn]+1
)
select * from roads_by_segment where [rn] = [c]
但是会出错(我尝试从俄语翻译):
Message 209, level 16, state 1, line 5
Ambiguous column name "road_id".
Message 209, level 16, state 1, line 5
Ambiguous column name "Segment_Id".
Message209, level 16, state 1, line 6
Ambiguous column name "road_id".
第 5 行和第 6 行:
row_number() over (partition by road_id order by Segment_Id) as [rn],
count(*) over (partition by road_id) as [c]
这里有什么问题?
更新
我从bluefeet
答案中做所有事情并得到新的错误:
on [a].segment_id = b.[segment_id]
它说:
Message 207, level 16, state 1, line 29
Ambiguous column name "segment_id".
Message 207, level 16, state 1, line 29
Ambiguous column name "segment_id".