http://www.perlmonks.org?node_id=1187238


in reply to Re: How to add columns with new row name using perl from mysql query?
in thread How to add columns with new row name using perl from mysql query?

Is it possible to add others column directly in the mysql query without modifying into the while loop changes using perl
sub pending_running_partition { $var_data_running = ""; $var_data_pending = ""; my $str= shift; $DBH = &connect or die "Cannot connect to the sql server \n"; $DBH->do("USE $str;"); my $stmt="select queue_name,jobs_pending,jobs_running from queues +order by jobs_pending,jobs_running DESC ;"; my $sth = $DBH->prepare( $stmt ); $sth->execute() or print "Could not insert_pending_running_partit +ion"; my $tmp = 0; while(my @row_array=$sth->fetchrow_array) { if ($tmp == 0) { $var_data_running .= "\[\"$row_array[0] \($row_array[2]\)\",$r +ow_array[2]\]"; $var_data_pending .= "\[\"$row_array[0] \($row_array[1]\)\",$r +ow_array[1]\]"; $tmp++; } else { $var_data_running .= ",\[\"$row_array[0] \($row_array[2]\)\",$ +row_array[2]\]"; $var_data_pending .= ",\[\"$row_array[0] \($row_array[1]\)\",$ +row_array[1]\]"; } } $sth->finish; $DBH->disconnect(); }
By the above mysql query i pick maximum to minimum level .Without modifying while loop is it possible to limit maximum 5 and remaining rows to be added and namew with new row called others.