These are my tables:
- Member :
Id, Points - CartRegister :
Id, Member_Id, CartId, RegisterDate, Point - SelectetMembers :
Id, Member_Id
Participants can register the cart in CartRegister , and in Member.Points All points earned by a member must be calculated and inserted. Therefore, I need to calculate all the points of each SelectedMembers and update the Member table, but I do not know how to implement it.
In my head is a script:
UPDATE [Member] SET [Points]= ( SELECT SUM([CR].[Point]) AS [AllPoints] FROM [CartRegister] AS [CR] WHERE [CR].[Member_Id] =
So, I am confused by what is the where clause in Select Sum(Point) if I use
WHERE [CR].[Member_Id] IN ( Select Member_Id From SelectedMembers )
Then the sum of all the members will be the same as the sum of all the members of Point, maybe I need something like foreach What is your suggestion?
Saeid source share