+-----------------+--------------+--------------+
| 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 |
+---------------+--------------+--------------+
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, details, 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, summary, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.