dbTalk Databases Forums  

"ORDER BY" question

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss "ORDER BY" question in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mr.Kane
 
Posts: n/a

Default "ORDER BY" question - 07-19-2006 , 05:53 PM






we are evalutating performance and so this is a query that put
together;

SELECT prcsname , prcstype , runcntlid, begindttm, enddttm ,
floor(((enddttm-begindttm)*24*60*60)/3600) || ' HOURS ' ||
floor((((enddttm-begindttm)*24*60*60) -
floor(((enddttm-begindttm)*24*60*60)/3600)*3600)/60) || ' MINUTES ' ||
round((((enddttm-begindttm)*24*60*60) -
floor(((enddttm-begindttm)*24*60*60)/3600)*3600 -
(floor((((enddttm-begindttm)*24*60*60) -
floor(((enddttm-begindttm)*24*60*60)/3600)*3600)/60)*60))) || ' SECS '
time_difference

FROM PSFT.psprcsrqst

WHERE begindttm > TO_DATE ('07-18-2006','MM-DD-YYYY')
ORDER BY time_difference DESC;

( I have tried to make it as intelligible as possible)

Anyway. the result set from running this looks something like this

PRCSNAME I PRCSTYPE I RUNCNTLID I BEGINDTTM I ENDDTTM I TIME_DIFFERENCE

The "TIME_DIFFERENCE" field has the following format
00 HOURS 00 MINUTES 00 SECS

unfortunately the "ORDER BY" sorts the result set in the following
curious order:

0 HOURS 6 MINS 13 SECS
0 HOURS 59 MINS 2 SECS
0 HOURS 56 MINS 34 SECS
0 HOURS 48 MINS 58 SECS
0 HOURS 4 MINS 24 SECS
0 HOURS 34 MINS 42 SECS
0 HOURS 31 MINS 20 SECS
etc

how can I adjust the ORDER BY clause to take this format into account,
so that it will sort in DESC order properly?

Thank you
Marc Kane
Intermediate SQL Programmer
and aspiring OCA 9i/10g professional


Reply With Quote
  #2  
Old   
Charles Hooper
 
Posts: n/a

Default Re: "ORDER BY" question - 07-19-2006 , 06:14 PM






Mr.Kane wrote:
Quote:
we are evalutating performance and so this is a query that put
together;

SELECT prcsname , prcstype , runcntlid, begindttm, enddttm ,
floor(((enddttm-begindttm)*24*60*60)/3600) || ' HOURS ' ||
floor((((enddttm-begindttm)*24*60*60) -
floor(((enddttm-begindttm)*24*60*60)/3600)*3600)/60) || ' MINUTES ' ||
round((((enddttm-begindttm)*24*60*60) -
floor(((enddttm-begindttm)*24*60*60)/3600)*3600 -
(floor((((enddttm-begindttm)*24*60*60) -
floor(((enddttm-begindttm)*24*60*60)/3600)*3600)/60)*60))) || ' SECS '
time_difference

FROM PSFT.psprcsrqst

WHERE begindttm > TO_DATE ('07-18-2006','MM-DD-YYYY')
ORDER BY time_difference DESC;

( I have tried to make it as intelligible as possible)

Anyway. the result set from running this looks something like this

PRCSNAME I PRCSTYPE I RUNCNTLID I BEGINDTTM I ENDDTTM I TIME_DIFFERENCE

The "TIME_DIFFERENCE" field has the following format
00 HOURS 00 MINUTES 00 SECS

unfortunately the "ORDER BY" sorts the result set in the following
curious order:

0 HOURS 6 MINS 13 SECS
0 HOURS 59 MINS 2 SECS
0 HOURS 56 MINS 34 SECS
0 HOURS 48 MINS 58 SECS
0 HOURS 4 MINS 24 SECS
0 HOURS 34 MINS 42 SECS
0 HOURS 31 MINS 20 SECS
etc

how can I adjust the ORDER BY clause to take this format into account,
so that it will sort in DESC order properly?

Thank you
Marc Kane
Intermediate SQL Programmer
and aspiring OCA 9i/10g professional
ORDER BY
(enddttm-begindttm) DESC

Sorting the records based on a numeric result comparision rather than
an ASCII text result comparision. '20000' < '3' but 20000 > 3

Charles Hooper
PC Support Specialist
K&M Machine-Fabricating, Inc.



Reply With Quote
  #3  
Old   
Robbert van der Hoorn
 
Posts: n/a

Default Re: "ORDER BY" question - 07-20-2006 , 04:13 AM




"Charles Hooper" <hooperc2000 (AT) yahoo (DOT) com> wrote

Quote:
Mr.Kane wrote:
we are evalutating performance and so this is a query that put
together;

SELECT prcsname , prcstype , runcntlid, begindttm, enddttm ,
floor(((enddttm-begindttm)*24*60*60)/3600) || ' HOURS ' ||
floor((((enddttm-begindttm)*24*60*60) -
floor(((enddttm-begindttm)*24*60*60)/3600)*3600)/60) || ' MINUTES ' ||
round((((enddttm-begindttm)*24*60*60) -
floor(((enddttm-begindttm)*24*60*60)/3600)*3600 -
(floor((((enddttm-begindttm)*24*60*60) -
floor(((enddttm-begindttm)*24*60*60)/3600)*3600)/60)*60))) || ' SECS '
time_difference

FROM PSFT.psprcsrqst

WHERE begindttm > TO_DATE ('07-18-2006','MM-DD-YYYY')
ORDER BY time_difference DESC;

( I have tried to make it as intelligible as possible)

Anyway. the result set from running this looks something like this

PRCSNAME I PRCSTYPE I RUNCNTLID I BEGINDTTM I ENDDTTM I TIME_DIFFERENCE

The "TIME_DIFFERENCE" field has the following format
00 HOURS 00 MINUTES 00 SECS

unfortunately the "ORDER BY" sorts the result set in the following
curious order:

0 HOURS 6 MINS 13 SECS
0 HOURS 59 MINS 2 SECS
0 HOURS 56 MINS 34 SECS
0 HOURS 48 MINS 58 SECS
0 HOURS 4 MINS 24 SECS
0 HOURS 34 MINS 42 SECS
0 HOURS 31 MINS 20 SECS
etc

how can I adjust the ORDER BY clause to take this format into account,
so that it will sort in DESC order properly?

Thank you
Marc Kane
Intermediate SQL Programmer
and aspiring OCA 9i/10g professional

ORDER BY
(enddttm-begindttm) DESC

Sorting the records based on a numeric result comparision rather than
an ASCII text result comparision. '20000' < '3' but 20000 > 3

Charles Hooper
PC Support Specialist
K&M Machine-Fabricating, Inc.

or by prefixing 1 digit values with '0' ('6 MINS' becomes '06 MINS' and
will sort ok). Not as beautiful as Charles' solution though...

Robbert




Reply With Quote
  #4  
Old   
Mr.Kane
 
Posts: n/a

Default Re: "ORDER BY" question - 07-20-2006 , 03:56 PM



Thank you both for your time on my issue.


-M


Robbert van der Hoorn wrote:
Quote:
"Charles Hooper" <hooperc2000 (AT) yahoo (DOT) com> wrote in message
news:1153350895.019503.45800 (AT) p79g2000cwp (DOT) googlegroups.com...
Mr.Kane wrote:
we are evalutating performance and so this is a query that put
together;

SELECT prcsname , prcstype , runcntlid, begindttm, enddttm ,
floor(((enddttm-begindttm)*24*60*60)/3600) || ' HOURS ' ||
floor((((enddttm-begindttm)*24*60*60) -
floor(((enddttm-begindttm)*24*60*60)/3600)*3600)/60) || ' MINUTES ' ||
round((((enddttm-begindttm)*24*60*60) -
floor(((enddttm-begindttm)*24*60*60)/3600)*3600 -
(floor((((enddttm-begindttm)*24*60*60) -
floor(((enddttm-begindttm)*24*60*60)/3600)*3600)/60)*60))) || ' SECS '
time_difference

FROM PSFT.psprcsrqst

WHERE begindttm > TO_DATE ('07-18-2006','MM-DD-YYYY')
ORDER BY time_difference DESC;

( I have tried to make it as intelligible as possible)

Anyway. the result set from running this looks something like this

PRCSNAME I PRCSTYPE I RUNCNTLID I BEGINDTTM I ENDDTTM I TIME_DIFFERENCE

The "TIME_DIFFERENCE" field has the following format
00 HOURS 00 MINUTES 00 SECS

unfortunately the "ORDER BY" sorts the result set in the following
curious order:

0 HOURS 6 MINS 13 SECS
0 HOURS 59 MINS 2 SECS
0 HOURS 56 MINS 34 SECS
0 HOURS 48 MINS 58 SECS
0 HOURS 4 MINS 24 SECS
0 HOURS 34 MINS 42 SECS
0 HOURS 31 MINS 20 SECS
etc

how can I adjust the ORDER BY clause to take this format into account,
so that it will sort in DESC order properly?

Thank you
Marc Kane
Intermediate SQL Programmer
and aspiring OCA 9i/10g professional

ORDER BY
(enddttm-begindttm) DESC

Sorting the records based on a numeric result comparision rather than
an ASCII text result comparision. '20000' < '3' but 20000 > 3

Charles Hooper
PC Support Specialist
K&M Machine-Fabricating, Inc.


or by prefixing 1 digit values with '0' ('6 MINS' becomes '06 MINS' and
will sort ok). Not as beautiful as Charles' solution though...

Robbert


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.