Account Entity Unit Jan Feb Mar Account01 Entity01 Unit01 1 2 3 Account01 Entity01 Unit01 4 5 6 Account01 Entity01 Unit01 7 8 9 Account02 Entity02 Unit02 10 11 12 #### Account Entity Unit Jan Feb Mar Account01 Entity01 Unit01 12 15 18 Account02 Entity02 Unit02 10 11 12 #### CREATE TABLE concat_FRA3 AS SELECT Account, Entity, Unit, SUM(Jan) Jan, SUM(Feb) Feb, SUM(Mar) Mar FROM concat_FRA2 GROUP BY Account, Entity, Unit; #### # Store my %storage; foreach my $row (@$result_set) { my $hash_key = encode_hash_key(row); my $new_row = $row; if (exists $storage{$hash_key}) { $new_row = merge_rows($row, $storage{$hash_key}); } $storage{$hash_key} = $new_row; }