sub calculating_pop_summations_B { my $sthZK_B = $dbh->prepare(" SELECT DISTINCT Aggregated_area FROM Geo_postaggregated_pop_count; ") or die "Couldn't prepare query: ".$dbh->errstr; $sthZK_B->execute() or die "Couldn't execute query: ".$sthZK_B->errstr; my @sthZK_B_A_array; while ( my @columns_B = $sthZK_B->fetchrow() ) { my $Aggregated_area = $columns_B[0]; my $sthZK_B_A = " UPDATE Geo_postaggregated_pop_count SET Sum_of_person_count = ( SELECT DISTINCT (SELECT SUM(G.Person_count) FROM Geo_postaggregated_pop_count G WHERE G.Sex = 1 AND G.Aggregated_area LIKE '".$Aggregated_area."')+ (SELECT SUM(G.Person_count) FROM Geo_postaggregated_pop_count G WHERE G.Sex = 2 AND G.Aggregated_area LIKE '".$Aggregated_area."') FROM Geo_postaggregated_pop_count G WHERE G.Aggregated_area LIKE '".$Aggregated_area."') FROM Geo_postaggregated_pop_count G WHERE G.Aggregated_area LIKE '".$Aggregated_area."' "; push (@sthZK_B_A_array, $sthZK_B_A); } foreach (@sthZK_B_A_array){ my $sthZK_C = $dbh->prepare(" ".$_." ") or die "Couldn't prepare query: ".$dbh->errstr; $sthZK_C->execute() or die "Couldn't execute query: ".$sthZK_C->errstr; } }