Note ; This assumes you don't have a prod called 'total'.#!perl use strict; use DBI; my $dbh = connect(..); my %pivot=(); my $total; my $sql = 'SELECT prod,count(*) FROM prod GROUP BY prod'; my $sth = $dbh->prepare($sql); $sth->execute(); while (my @f = $sth->fetchrow_array){ $pivot{$f[0] || 'null' } = $f[1]; $total += $f[1]; } my @cols = sort keys %pivot; unshift @cols,'total'; $pivot{'total'} = $total; print sprintf "| %5s ",$_ for @cols; print "|\n"; print sprintf "| %5d ",$pivot{$_} for @cols; print "|\n";
In reply to Re^2: return string from query (DBI, MySQL) got truncated when trying to generating statement dynamically for MySQL
by poj
in thread return string from query (DBI, MySQL) got truncated when trying to generating statement dynamically for MySQL
by khandielas
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |