Re: Sorting
Posted in 1996
arcieri@pilot.njin.net (Joseph Arcieri) wrote:
>
>Hi, I'm having a bit of trouble... I have a simple report that lists
>employees birthdays. The report uses .. "where month(date_of_birth)=month"
>
>How can I sort this report by month (or can't it be done?) I have the
>Informix manuals and some 3rd party books but can't seem to get it!! I
>thought it would be (or would like it to be) something simple as
>...order by month(date_of_birth)
>
>Can anyone point me in the right direction? Thanks, Joe
>
Hi Joseph,
first, you'll have to select the same expression, e.g:
SELECT col_a, month(date_of_birth) FROM xxx WHERE ...Then there are 2 solutions:
1.) You use a column alias in the SELECT, e.g.:
SELECT col_a, month(date_of_birth) mon -- mon is the alias here
FROM table WHERE month(date_of_birth)=month
ORDER BY mon
2.) You use column numbers in your ORDER BY, e.g.:
SELECT col_a, month(date_of_birth)
FROM table WHERE month(date_of_birth)=month
ORDER BY 2 -- 2 indicates the 2nd column of the SELECT-clause
Hope this helps,
Peter
Peter Kolmhofer
DBA
Porsche Informatik, Austria
email: kop@szg.porsche.co.at