I have a (SQL Server) table similar to the following:
SalesSummary
Year | Team | Person | Person Sales | Team Sales/Yr
2013
Assuming you are using SQL Server, I think you want something like this:
WITH toupdate AS
(SELECT team, year,
Sum(personsales) OVER (partition BY team, year) AS newTeamSales
FROM salessummary
)
UPDATE toupdate
SET teamsales = newteamsales;
Your original query has several issues and suspicious constructs. First, an aggregation subquery is not updatable. Second, you are doing an aggregation and using a window function with, although allowed, is unusual. Third, you are aggregating by PersonSales
and taking the sum()
. Once again, allowed, but unusual.