我有一个关于在 Update 语句中使用子查询的问题。我的例子:
UPDATE TRIPS
SET locations = city + ', ' FROM (select Distinct city
from poi
where poi.trip_guid = trips.guid)
是否可以在子查询中引用主表值(trips.guid)?
当我尝试使用时trips.guid
我收到错误:
“无法绑定多部分标识符“trips.guid”。”
“select Distinct city from poi”子句返回多个城市。
你可以尝试类似的东西
UPDATE trips
SET locations = t.city + ', ' + poi.city
FROM trips t INNER JOIN
(
select Distinct city, trip_guid from poi
) poi ON t.trip_guid = poi.trip_guid
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)