Something like this (not tested code):
my $BaseQuery " select count(*) from owner"; my $WhereClause = " where rent_car = '?'"; # Get the total number of rows in the table. my $sth = $dbh->prepare ( $BaseQuery ); my $Total = $sth->fetchrow_array(); # Initialize a total in order to be able to calculate # "Other" responses" my $SoFar = 0; # Prepare the longer query. $sth = $dbh->prepare ( $BaseQuery . $WhereClause ); # Loop through valid responses. my %Responses = ( Y => "Yes", N => "No" ); foreach ( keys %Responses ) { $sth->execute ( $_ ); my $ThisChoice = $sth->fetchrow_array(); $SoFar += $ThisChoice; my $Result = sprintf ( "%3.1f%%", $ThisChoice / $Total ); print qq ( <tr><td>$Responses{ $_ }</td><td>$Result</td></tr> ); } # Figure out how many "Other" responses there were. my $Result = sprintf ( "%3.1f%%", ( $Total - $SoFar ) / $Total ); print qq ( <tr><td>Other</td><td>$Result</td></tr> );
--t. alex
"There was supposed to be an earth-shattering kaboom!" --Marvin the Martian
In reply to Re: Perl - MySQL query question
by talexb
in thread Perl - MySQL query question
by peppiv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |