INSERT INTO traffic_data_aggregated_lanes
( aggregated_speed )
SELECT product
FROM temp_aggregated_speed
JOIN temp_aggregated_speed
ON traffic_data_aggregated_lanes.ID = temp_aggregated_speed.ID
AND traffic_data_aggregated_lanes.date = temp_aggregated_speed.datetime;
在进行上述查询时,我遇到了一个错误。
Msg 1013, Level 16, State 1, Line 1
"temp_aggregated_speed"
子句中的对象"temp_aggregated_speed"
和FROM
具有相同的公开名称。使用相关名来区分它们。
答案 0 :(得分:0)
您是自我加入,只需为每个不同的“实例”使用一个不同的别名
Select product from temp_aggregated_speed
JOIN
temp_aggregated_speed ON
更改为
Select tas1.product from temp_aggregated_speed tas1
JOIN
temp_aggregated_speed tas2 ON
答案 1 :(得分:0)
从它的外观来看,您可能正在尝试更新traffic_data_aggregated_lanes
中现有行的列,在这种情况下,语法应该是更新:
UPDATE l
SET l.aggregated_speed = s.product
FROM
traffic_data_aggregated_lanes l
INNER JOIN temp_aggregated_speed s
ON l.ID = s.ID
AND l.date = t.datetime;