nisupport
asked on
How do I perform a calculation in an update query?
I need to perform a query that first calculates the total weight for a category. There are not a set number of categories. Then I need to take the total weight for each category and update the weights withing that category by dividing the current value by the sum. Any help is appreciated on this.
UPDATE Testing SET weight = weight/b.weight
FROM Testing a
inner join
(
SELECT SUM(weight) as 'weight' FROM Testing GROUP BY category
) b on a.Category = b.Category
this query seems to be correct!
what error do you receive when run this statement?
try code below it's with alias names now
what error do you receive when run this statement?
try code below it's with alias names now
UPDATE Testing SET a.weight = a.weight/b.weight
FROM Testing a
inner join
(
SELECT SUM(weight) as 'weight' FROM Testing GROUP BY category
) b on a.Category = b.Category
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I could not understand the logic here...