Here i had added my part of subroutine and mentioned only the part of the error which i struck with to complete it.
sub datas { $data1 = ""; $data2 = ""; my $str= shift; $DBH = &connect or die "Cannot connect to the sql server \n"; $DBH->do("USE $str;"); my $stmt="select name,data1,data2 from((select name,data1,data2 fr +om datas order by data1 +data2 desc limit 5 )union all(select 'added +' as name ,sum(data1) as data1 ,sum(data2) as data2 from (select dat +a1,data2 from datas order by data2+data1 desc limit 1844674407370955 +1615 offset 5 ) new)) new;"; my $sth = $DBH->prepare( $stmt ); $sth->execute() or die $sth->errstr; my $tmp = 0; while(my @row_array=$sth->fetchrow_array) { if ($tmp == 0) { $data1 .= "\[\"$row_array[0] \($row_array[2]\)\",$row_array[2] +\]"; $data2 .= "\[\"$row_array[0] \($row_array[1]\)\",$row_array[1] +\]"; $tmp++; } else { $data1 .= ",\[\"$row_array[0] \($row_array[2]\)\",$row_array[2 +]\]"; $data2 .= ",\[\"$row_array[0] \($row_array[1]\)\",$row_array[1 +]\]"; } } $sth->finish; $DBH->disconnect(); }

Here i hsd done sorting by considering the name common for both data1 and data2.Instead i should take name+data1 and name+data2 independently.
Here i want to sort the both data1 and data2 from maximum to minimum level.But from my above code only the data2 get sorted data1 is not sorted from maximum to minimum level.
How can sort both columns independently
. Help me to fix my mistake.Thanks in advance for any help.
obtained output: +--------------+--------------+--------------+ | name | data1 | data2 | +--------------+--------------+--------------+ | dsp_ncsim_hp | 11262 | 82 | | adice_short | 2865 | 274 | | ncsim_long | 741 | 116 | | adice_ncsim | 109 | 150 | | normal | 133 | 31 | | others | 5 | 184 | +--------------+--------------+--------------+ Expected: Jobs_running need to be changed.Here jobs_running column is fetching a +s per jobs_pending column.Jobs_pending should be sorted from maximum +to minimum level as per queue_name.Here jobs_running column is not ar +ranged from maximum to minimum level. +--------------+--------------+--------------+ | queue_name | data1 | data2 | +--------------+--------------+--------------+ | dsp_ncsim_hp | 11262 | 82 | | adice_short | 2865 | 274 | | ncsim_long | 741 | 116 | | adice_ncsim | 109 | 150 | | normal | 133 | 31 | | others | 5 | 184 | +--------------+--------------+--------------+ In the above table running is not in this order.How can i sort jobs_ru +nning and jobs_pending independently by its value. For jobs_running:- +-------------+--------------+--+ | name | data1 | +--------------+---------------+ |adice_short | 274 | | adice_ncsim | 150 | | ncsim_long | 116 | | dsp_ncsim_hp | 82 | | normal | 31 | | others | 184 | +--------------+---------------+ For jobs_pending:- +--------------+--------------+ | name | data2 | +--------------+--------------+ | dsp_ncsim_hp | 11262 | | adice_short | 2865 | | ncsim_long | 741 | | adice_ncsim | 109 | | normal | 133 | | others | 5 | +--------------+--------------+

In reply to perl sql to separate and sort the column separately? by gpssana

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, 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:
    & &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.