3
我有一個名爲x.txt與以下數據的文本文件:的Perl - DBI :: CSV排序問題
emailid,hits
aa,100
bb,200
cc,300
dd,400
ee,500
aa,400
和我的Perl代碼
use DBI;
$dbh = DBI->connect ("dbi:CSV:", undef, undef, { f_dir => ".",csv_sep_char => "," });
my $query = "SELECT emailid,sum(hits) tothits FROM x.txt group by emailid order by tothits desc";
my $sth = $dbh->prepare ($query);
$sth->execute();
while (my $row = $sth->fetchrow_hashref) {
print $row->{emailid},"--",$row->{tothits},"\n";
}
$sth->finish();
返回
cc--300
bb--200
dd--400
aa--500
ee--700
這裏怎麼回事?
你也有「ee,200」嗎? – Tim