Use the stored procedure to eliminate data redundancy in the database
Create Procedure SP_MYTEST AS
Declare @pro varchar (50)
Declare @MM INT
Declare Wu Cursor for Select DistINCT Product from MyTest
Open wu
Fetch next from wu @Pro
While @@ fetch_status = 0
Begin
SELECT @ mm = sum ([COST]) from mytest where [product] = @ pro
Delete from mytest where [product] = @ pro
INSERT INTO MyTest ([Product], [COST]) VALUES (@ pro, @ mm)
Fetch next from wu @Pro
end
Close Wu
Deallocate wu
Go
We can use jobs to update the corresponding data