niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » Oracle
"ORDER BY" question
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
Author Message
Mr.Kane
*nix forums beginner


Joined: 19 Jul 2006
Posts: 2

PostPosted: Wed Jul 19, 2006 10:53 pm    Post subject: "ORDER BY" question Reply with 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
Back to top
Charles Hooper
*nix forums addict


Joined: 09 Jul 2006
Posts: 51

PostPosted: Wed Jul 19, 2006 11:14 pm    Post subject: Re: "ORDER BY" question Reply with quote

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.
Back to top
Robbert van der Hoorn
*nix forums beginner


Joined: 29 Jun 2006
Posts: 16

PostPosted: Thu Jul 20, 2006 9:13 am    Post subject: Re: "ORDER BY" question Reply with quote

"Charles Hooper" <hooperc2000@yahoo.com> wrote in message
news:1153350895.019503.45800@p79g2000cwp.googlegroups.com...
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
Back to top
Mr.Kane
*nix forums beginner


Joined: 19 Jul 2006
Posts: 2

PostPosted: Thu Jul 20, 2006 8:56 pm    Post subject: Re: "ORDER BY" question Reply with quote

Thank you both for your time on my issue.


-M


Robbert van der Hoorn wrote:
Quote:
"Charles Hooper" <hooperc2000@yahoo.com> wrote in message
news:1153350895.019503.45800@p79g2000cwp.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
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
The time now is Fri Nov 21, 2008 8:50 pm | All times are GMT
navigation Forum index » Databases » Oracle
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Newbie question: How to forward a domain to a mailbox? leei Postfix 0 Fri Aug 24, 2007 4:55 pm
No new posts configuration question for httpd Karl Wang Apache 1 Fri Jul 21, 2006 2:10 pm
No new posts nim problem/question Ron AIX 0 Fri Jul 21, 2006 1:57 pm
No new posts question for JAVA developer who r using postgres sql as b... deepak pal PostgreSQL 1 Fri Jul 21, 2006 9:00 am
No new posts Encryption Question dtuttle1@gmail.com Berkeley DB 2 Thu Jul 20, 2006 10:09 pm

Debt Consolidation | Mobile Phones | Credit Card | Loans | Remortgages
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.3057s ][ Queries: 16 (0.2135s) ][ GZIP on - Debug on ]