in reply to SQL or Perl solution

You should be able to do this in a single update
UPDATE Geo_postaggregated_pop_count_Ward SET Sum_male_count = (SELECT SUM(G.Person_count) FROM Geo_postaggregated_pop_count_Ward G WHERE Sex = 1), Sum_female_count = (SELECT SUM(G.Person_count) FROM Geo_postaggregated_pop_count_Ward G WHERE Sex = 2), Sum_of_person_count = (SELECT SUM(G.Person_count) FROM Geo_postaggregated_pop_count_Ward G WHERE Sex = 1 OR Sex = 2);
This assumes you can afford the large lock this would generate. Otherwise use a Transact SQL cursor.

Hope it helps
UnderMine

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.