假设您正在使用SQL Server,我认为您需要这样的东西:
WITH toupdate AS (SELECT team, year, Sum(personsales) OVER (partition BY team, year) AS newTeamSales FROM salessummary ) UPDATE toupdate SET teamsales = newteamsales;
您的原始查询存在多个问题和可疑的结构。首先,聚合子查询不可更新。其次,您正在进行聚合,并且使用窗口功能(尽管允许)与众不同。第三,你被聚集
PersonSales,并采取
sum()。再次允许,但不寻常。



