I'm reading from a MySQL database using DBI/DBD. I want to be able to read the results that equal a certain query, print them, their count, their percentage to another number (not important what number it is) and print them in order by count.

Here's what I'm using (could be written better than this I'm sure):

my $sth = $dbh->prepare('SELECT DISTINCT surveys, COUNT(*) FRO +M neverland GROUP BY surveys ORDER BY surveys DESC'); $sth->execute() or die $sth->errstr; while (my @result = $sth->fetchrow_array()) { my $percent = (@result[1] / $nothernumber)*100; printf qq(<tr><td><font size="2" face="Arial">@result[0]</font +></td><td><font size="2" face="Arial">@result[1]</font></td><td align +="right"><font face="arial" size="2">%.1f%%</td></tr>\n),$percent; }

This gives me something like this:

monkeys
gorillas
bats
8
9
2
17%
25%
5%


I'd like it to return this:

gorillas
monkeys
bats
9
8
2
17%
25%
5%


ORDER BY COUNT doesn't work. I put in ORDER BY DESC just to see how far I could take it. Any ideas?

TIA

peppiv

"Lost in (cyber) Space"

In reply to ORDER BY COUNT(*)? by peppiv

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.