> select job_coop as 'Job/Coop', count(*) as Count from queue group by
> job_coop order by Count;


The other alternative is to omit the 'as Count' and use this query:

select job_coop as 'Job/Coop', count(*)
from queue
group by job_coop
order by 2;

where the '2' in the 'order by' is the number of the column you are sorting.
(The count(*) expression is the second column of the result set so you
replace it with a 2). This saves you from having to use an 'As' expression
for 'count(*)' although it makes the query less clear too. (It won't be
apparent to some people what the effect of the '2' in the 'order by' is.)

Rhino

----- Original Message ----- 
From: "Michael Kruckenberg" <[EMAIL PROTECTED]>
To: "Dirk Bremer (NISC)" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, May 12, 2004 9:46 AM
Subject: Re: ORDER BY Question


> Dirk Bremer (NISC) wrote:
> > The following query produces the following results:
> >
> > select job_coop as 'Job/Coop', count(*) as Count from queue group by
> > job_coop;
> >
> > +----------+-------+
> > | Job/Coop | Count |
> > +----------+-------+
> > | B03013   |    19 |
> > | B05044   |     9 |
> > | B07037   |     6 |
> > | B15037   |     4 |
> > | B16032   |     6 |
> > | B17026   |     6 |
> > | B17056   |    18 |
> > | B18032   |     5 |
> > | B20009   |    31 |
> > | B21012   |     1 |
> > | B24026   |     8 |
> > | B25001   |    42 |
> > | B27043   |    10 |
> > | B27047   |     8 |
> > | B29064   |     6 |
> > | B31004   |    61 |
> > | B36035   |    60 |
> > | B36529   |    54 |
> > | B38023   |    38 |
> > | B38034   |     7 |
> > | B40020   |    30 |
> > | D18032   |    31 |
> > | D27047   |     2 |
> > | D31004   |    59 |
> > +----------+-------+
> >
> > Is there a way to use the ORDER BY clause to order the results by the
> > numeric value of the count(*), i.e. so that the results would be sorted
by
> > the result of the count(*)?
>
> select job_coop as 'Job/Coop', count(*) as Count from queue group by
> job_coop order by Count;
>
>
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]
>


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to