#!/usr/bin/perl use DBI; use DBD::mysql; my $platform = "mysql"; my $database = "db_name"; my $host = "host_name"; my $port = "port_num"; my $tablename = "hist"; my $user = "user_name"; my $pwd = "pass"; open(STDOUT, ">C:\\perlscripts\\new.txt") || die "Can't open the file"; my $dsn = "dbi:mysql:$database:$host:$port"; my $dbh = DBI->connect($dsn,$user,$pwd) || die "Could not connect: $DBI::errstr\n"; my $query = $dbh->selectall_arrayref("select cus,ta,sum(gd1) as gd1,sum(gd2) as gd2 from hist group by cus,ta order by cus", {Slice => {} }); my $query2 = $dbh->selectall_arrayref("select cus,ta,sum(gd1),sum(gd2) from current group by cus,ta order by cus", {Slice => {} }); foreach my $ref (@$query) { push(@{$arry}, join(",",$ref->{cus},$ref->{ta},$ref->{gd1},$ref->{gd2}))."\n"; } foreach my $ref (@$query2) { push(@{$arry2}, join(",",$ref->{cus},$ref->{ta},$ref->{gd1},$ref->{gd2}))."\n";