in reply to Perl - MySQL query question

I would not use the cut-and-paste method that you've used -- make an array of the response that you want to count, and count those up. I would also count up all of the responses. What's left over is the 'other'.

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