Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: sorting tables by multiple columns

Re: sorting tables by multiple columns

From: Jeff Guttadauro <jeff109_at_NOSPAM.netscape.net>
Date: Thu, 29 Jul 1999 20:58:38 GMT
Message-ID: <37a0bbb5.27343417@news>


Hi, Markus.

        It looks like you actually want to sort by the DAY first, then the Name, and finally the TIME. Try something like this:

select name, timestamp from your_table
order by to_number(to_char(timestamp,'YYYYMMDD')), name, to_number(to_char(timestamp,'HH24MISS'))

Hope is what you are after.
-Jeff

On Wed, 28 Jul 1999 00:56:53 -0800, Markus Banach <h0444vcs_at_rz.hu-berlin.de> wrote:

>Dear Participants,
>
>I have the following problem (table) :
>
>NAME TIMESTAMP
>----- --------------------
>bernd 22-MAY-1999 13:25:25
>myra 22-MAY-1999 13:25:57
>bernd 22-MAY-1999 13:33:21
>myra 22-MAY-1999 13:34:55
>bernd 22-MAY-1999 13:36:03
>bernd 23-MAY-1999 00:04:17
>myra 23-MAY-1999 06:54:57
>
>I want to sort the table by Name (first priority) and then
>by the day (from timestamp) (sec. priority). The desired
>output should be :
>
>NAME TIMESTAMP
>----- --------------------
>bernd 22-MAY-1999 13:25:25
>bernd 22-MAY-1999 13:33:21
>bernd 22-MAY-1999 13:36:03
>myra 22-MAY-1999 13:25:57
>myra 22-MAY-1999 13:34:55
>bernd 23-MAY-1999 00:04:17
>myra 23-MAY-1999 06:54:57
>
>Using order by didn't help me on. I tried the following :
>
>SQL> ALTER SESSION SET NLS_DATE_FORMAT = 'DD' ;
>SQL> select *
> 2 from sort
> 3 order by name, timestamp
> 4 /
>
>NAME TI
>----- --
>bernd 22
>bernd 22
>bernd 22
>bernd 23
>myra 22
>myra 22
>myra 23
>
>7 rows selected.
>
>Your help will be greatly appreciated !
>
>Markus
>
>
>
>* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
>The fastest and easiest way to search and participate in Usenet - Free!
Received on Thu Jul 29 1999 - 15:58:38 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US