Home » SQL & PL/SQL » SQL & PL/SQL » How the following query order the result starting from monday?
How the following query order the result starting from monday? [message #19783] Tue, 09 April 2002 14:06 Go to next message
dilshad
Messages: 2
Registered: April 2002
Junior Member
How the following query order the result starting from monday? please explain the logic behind it.

1 select ename,sal,hiredate,to_char(hiredate,'d') ,to_char(hiredate,'day') day,
2 to_char(hiredate-1,'day') "day -1",to_char(hiredate-1,'d')
3 from emp
4* order by to_char(hiredate-1,'d')
Re: How the following query order the result starting from monday? [message #19785 is a reply to message #19783] Tue, 09 April 2002 15:23 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
The order by clause is taking the hiredate, then subtracting a day from that, and then converted that "day before the hiredate" into a numeric day of the week (Sunday = 1, Monday = 2, etc.).

So, technically, it is ordered by the day of the week corresponding to the day before the hiredate.
Previous Topic: calculate rows of user tables
Next Topic: Creating a Read-Only User
Goto Forum:
  


Current Time: Fri Apr 19 16:08:36 CDT 2024