Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
+-----------------+--------------+--------------+ | queue_name | jobs_pend | jobs_run | +-----------------+--------------+--------------+ | adice_long | 5 | 39 | | adice_ncsim | 0 | 6 | | adice_short | 254 | 192 | | calibre | 0 | 0 | | dsp_ncsim_gls | 0 | 2 | | dsp_ncsim_hp | 0 | 2 | | dsp_ncsim_lp | 0 | 5 | | dsp_ncsim_mp | 0 | 5 | | hcg_ncsim_comp | 0 | 0 | | hcg_ncsim_hp | 0 | 9 | | hcg_ncsim_lp | 0 | 0 | | hcg_ncsim_mp | 0 | 0 | | hcg_ncsim_short | 0 | 0 | | ipdc_pte | 0 | 0 | | ncsim_long | 41 | 78 | | ncsim_lp | 1 | 4 | | ncsim_short | 0 | 84 | | normal | 170 | 30 | | spectreRF | 0 | 1 | | vcs | 0 | 0 | +-----------------+--------------+--------------+

I had created the following sub routine to display the values.
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_pend,jobs_run from queues;"; my $sth = $DBH->prepare( $stmt ); $sth->execute() or print "Could not in7sert_run_pend data"; 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(); }

Now my query is i want to take maximum of 5 from the above table and the remaining table values should be sum it added with new row name called others.So i had tried the following script
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_pend,jobs_run from queues order b +y queue_name limit 5;"; my $sth = $DBH->prepare( $stmt ); $sth->execute() or print "Could not in7sert_run_pend data"; 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(); }
So the result of the above modified sub routine will be as follows
+---------------+--------------+--------------+ | queue_name | jobs_pend | jobs_run | +---------------+--------------+--------------+ | adice_long | 5 | 39 | | adice_ncsim | 0 | 6 | | adice_short | 254 | 192 | | calibre | 0 | 0 | | dsp_ncsim_gls | 0 | 2 | +---------------+--------------+--------------+
So now the remaining rows are missing from the table .Those rows should be summed and appended with the name called others
Expected output:
+---------------+--------------+--------------+ | queue_name | jobs_pend | jobs_run | +---------------+--------------+--------------+ | adice_long | 5 | 39 | | adice_ncsim | 0 | 6 | | adice_short | 254 | 192 | | calibre | 0 | 0 | | dsp_ncsim_gls | 0 | 2 | | others | 212 | 218 | +---------------+--------------+--------------+

In reply to How to add columns with new row name using perl from mysql query? by perlanswers

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (3)
    As of 2020-10-25 13:35 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favourite web site is:












      Results (249 votes). Check out past polls.

      Notices?