我在 SQL 中创建了一个“事务”表,如下所示:
TransactionID Date AccountNumber Type Amount
657520 02-07-1999 016901581432 Debit 16000
657524 02-07-1999 016901581432 Debit 13000
657538 09-07-1999 016901581432 Credit 11000
657548 18-07-1999 016901581432 Credit 15500
657519 02-07-1999 016901581433 Debit 12000
657523 02-07-1999 016901581433 Credit 11000
657529 03-07-1999 016901581433 Debit 15000
657539 10-07-1999 016901581433 Credit 10000
657541 11-07-1999 016901581434 Debit 12000
657525 03-07-1999 016901581434 Debit 15000
657533 05-07-1999 016901581434 Credit 12500
我必须使用数据库找到每个帐户的总借方金额和总贷方金额。我的代码是这样的:
#!/usr/bin/perl
use DBI;
use strict;
use warnings;
print "content-type:text/html\n\n";
$dbh = DBI->connect('dbi:___','prithvi','*password*') or die "Couldn't connect";
my %trans;
my $tran = $dbh->prepare("SELECT * FROM `transaction` LIMIT 0 , 11");
$tran->execute;
while(my @row = $tran->fetchrow_hash)
{
my $tran = join ',', @row;
$trans{$tran[2]}{$tran[3]} += $tran[4];
}
foreach my $acno(sort keys %trans)
{
print "Total Amount deposited and total amount credited for Account Number $acno is Rs.$trans{$acno}{'Debit'} and Rs.$trans{$acno}{'Credit'}\n";
}
$tran->finish;
$dbh->disconnect;
我哪里错了?