in reply to Re: return string from query (DBI, MySQL) got truncated when trying to generating statement dynamically for MySQL
in thread return string from query (DBI, MySQL) got truncated when trying to generating statement dynamically for MySQL
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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: return string from query (DBI, MySQL) got truncated when trying to generating statement dynamically for MySQL
by khandielas (Sexton) on Jul 24, 2013 at 21:18 UTC | |
by poj (Abbot) on Jul 24, 2013 at 22:19 UTC |