It works if you alias the id, then it's just a normal GROUP BY on the first column (1) to get the sums

SELECT CASE WHEN num <= @row_limit THEN queue_name ELSE 'others' END name, num, queue_name, jobs_pend, jobs_run FROM ( SELECT @row_num := @row_num + 1 as num, queue_name, jobs_pend, jobs_run FROM queues, (SELECT @row_num := 0, @row_limit:=5) r ) q

gives

name num queue_name jobs_pend jobs_run adice_long 1 adice_long 5 39 adice_ncsim 2 adice_ncsim 0 6 adice_short 3 adice_short 254 192 calibre 4 calibre 0 0 dsp_ncsim_gls 5 dsp_ncsim_gls 0 2 others 6 dsp_ncsim_hp 0 2 others 7 dsp_ncsim_lp 0 5 others 8 dsp_ncsim_mp 0 5 others 9 hcg_ncsim_comp 0 0 others 10 hcg_ncsim_hp 0 9 others 11 hcg_ncsim_lp 0 0 others 12 hcg_ncsim_mp 0 0 others 13 hcg_ncsim_short 0 0 others 14 ipdc_pte 0 0 others 15 ncsim_long 41 78 others 16 ncsim_lp 1 4 others 17 ncsim_short 0 84 others 18 normal 170 30 others 19 spectreRF 0 1 others 20 vcs 0 0
poj

In reply to Re^9: How to add columns with new row name using perl from mysql query? by poj
in thread 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, 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.