How to calculate data from different cells in

Hi there. I need to calculete different cells’s data in my RG, how can I do that?
For example, in the RG there is a NAME cell and a COST cell, suppose NAME is " 1" in the first row, “2” in the second row, and “1” again in the 3rd row, how to calculate the cost of only the rows with the name “1”?

Check out my examples: