Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: How to add columns with new row name using perl from mysql query?

by finddata (Sexton)
on Apr 06, 2017 at 10:02 UTC ( #1187238=note: print w/replies, xml ) Need Help??


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.
  • Comment on Re^2: How to add columns with new row name using perl from mysql query?
  • Download Code

Replies are listed 'Best First'.
Re^3: How to add columns with new row name using perl from mysql query?
by poj (Abbot) on Apr 06, 2017 at 12:29 UTC
    Is it possible..

    Yes

    Without modifying while loop..

    No ( unless you make the SQL more complex )

    Note the error message for your select is still wrong here

    $sth->execute() or print "Could not in7sert_run_pend data"; 
    
    poj

      Here i should not change the while loop.Without changing while loop, by using only sql query how can i do it?Will adding duplicate entries of the mysql rows and unique it will helps me.If it helps how can i do it mysql query.

        by using only sql query how can i do it

        Not a Perl question then ?

        Develop your SQL in MySQL Workbench (or other client) and then when it works put it in your perl script

        poj

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1187238]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2019-12-13 00:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?