【发布时间】:2026-02-05 18:55:01
【问题描述】:
我想知道以下查询:
UPDATE statisticsTable
SET Value = (select count(*)
FROM OtherTable o
WHERE o.UserId = UserId ) <-- this is the part that concerns me
WHERE id in (1,2,3)
SQL Server 如何知道第二个“UserId”字段来自 statisticsTable 而不是来自 OtherTable ?
为什么我不能为统计表提供别名,例如 'stat' 以阐明我想从哪里获得该 UserId ?或者有什么办法?
【问题讨论】:
-
这工作正常吗?我通常会做类似
WHERE o.UserId = statisticsTable.UserId的事情。 -
你不能在你的子查询中有
UPDATE statisticsTable as s然后有WHERE o.UserID = s.UserId吗?我还没有测试过这个。我从未有过需要子查询的 UPDATE。
标签: sql sql-server sql-update