Geeks Talk

Prepare for your Next Interview




Order By Day Of week

This is a discussion on Order By Day Of week within the Oracle forums, part of the Databases category; I am having the select statement which is returning me the Day of the Week,ie. Mon, Tue, Wed etc. I need to order these days starting from Sunday and ...


Go Back   Geeks Talk > Databases > Oracle

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 05-03-2008
Junior Member
 
Join Date: May 2008
Location: Bangalore
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
Vasanth.sql is on a distinguished road
Order By Day Of week

I am having the select statement which is returning me the Day of the Week,ie. Mon, Tue, Wed etc.
I need to order these days starting from Sunday and ending on Saturday.
Kindly let me know how to write a SQL script for this.
Reply With Quote
The Following User Says Thank You to Vasanth.sql For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 05-03-2008
Junior Member
 
Join Date: Feb 2007
Location: India
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
tonyrobert is on a distinguished road
Re: Order By Day Of week

To get the desired result in your question use :
select * from table order by to_char(date_column,'D') ;

In the employees table we have hire_date column which is of datatype DATE.
select hire_date from employees order by to_char(hire_date,'D');

To check this thoroughly try the below query:
select hire_date, to_char(hire_date,'Dy'), to_char(hire_date,'D') dt from employees order by dt;
Reply With Quote
  #3 (permalink)  
Old 05-04-2008
Junior Member
 
Join Date: May 2008
Location: Bangalore
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
Vasanth.sql is on a distinguished road
Re: Order By Day Of week

Quote:
Originally Posted by tonyrobert View Post
to get the desired result in your question use : select * from table order by to_char(date_column,'d') ; in the employees table we have hire_date column which is of datatype date. select hire_date from employees order by to_char(hire_date,'d'); to check this thoroughly try the below query: select hire_date, to_char(hire_date,'dy'), to_char(hire_date,'d') dt from employees order by dt;
appreciate your quick reply. The above solution works if i have a date column but not the day of week string ( mon, tue etc) i have a sub query. My requirement is get the data for all the weekdays of a month along with the sum of everything and then order by day of week. So my query looks like this (get the rows from ((get the data for day of week-7 rows - from (get the data for each day-30 rows)) union (get the sum of 30 days)) order by day of week eg: innermost subquery ( sub 1) - (date, day of week, value)( returned column) next level subquery ( sub 2) - (day of week, value) total valued query ( total 1) - (null, value) outer most query - day of week, value - order by day of week outer query from ( sub2 from ( sub 1)) union total 1) order by day of week.
Reply With Quote
  #4 (permalink)  
Old 05-05-2008
Expert Member
 
Join Date: Sep 2007
Posts: 754
Thanks: 22
Thanked 62 Times in 61 Posts
krishnaindia2007 is on a distinguished road
Re: Order By Day Of week

Dear Vasanth ,

Post your table sructure and sample data to get quick reply from members.

Regards
Krishna
Reply With Quote
  #5 (permalink)  
Old 05-23-2008
Junior Member
 
Join Date: May 2008
Location: Bangalore
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
chandra.pc is on a distinguished road
Re: Order By Day Of week

SELECT *
FROM
ORDER BY TO_CHAR(datecolumn,'D');
Reply With Quote
Reply

  Geeks Talk > Databases > Oracle


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
pls order please lak211 ASP.NET 2 06-03-2008 04:33 AM
BO Designer Last week of the month jd_usnj Data Warehousing 1 05-22-2008 02:00 AM
Need to have day of the week srinivasa.dinesh Unix/Linux 0 03-19-2008 04:01 AM
Redirect to week.php instead of login.php Geek_Guest PHP 0 05-16-2007 01:10 PM
Display record ordered by the day of the week orlando SQL 3 03-01-2007 02:04 AM


All times are GMT -4. The time now is 03:15 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved