How can we order the column of day (mon to sun)such that monday comes first then tues and so no.Suppose we have retrieved day out of hiredate column

Showing Answers 1 - 43 of 43 Answers

Madhuri

  • Sep 17th, 2006
 

select hire_date, to_char(hire_date, 'day') as day from employees order by to_char(hire_date, 'd')

Divya

  • Sep 20th, 2006
 

thanks Madhuri...

but the result i m getting is in the order from sun then mon till sat(sun to sat)..

but i want to order it from mon then tue till sun(mon to sun).

If possible, plzz tell me the query for that.

  Was this answer useful?  Yes

Hari

  • Sep 22nd, 2006
 

hi divya! its simple. Note down the query.select to_char(hiredate,'day') from emp order by to_char(hiredate-1,'d')then u'll get d result as u like

Divya

  • Sep 27th, 2006
 

Thanks Hari,

now i m getting the desired output...

  Was this answer useful?  Yes

sushil

  • Oct 9th, 2006
 

Hi dea

ur answer is a  bit wrong its because it thn give u the output as sun to sat and not mon to sun

rgds.

-Sushil

  Was this answer useful?  Yes

sushil

  • Oct 9th, 2006
 

select to_char(hiredate,'day') from emp order by to_char(hiredate-1,'d')

deepak singh

  • Nov 7th, 2006
 

if you want to accurate answare then you excu. this query...........................select TRUNC(SYSDATE) date, to_char(SYSDATE,'day') day from DUAL order by to_char(TRUNC(SYSDATE)-1,'d')

vamsee krishna

  • Nov 10th, 2006
 

Hi Deepak,

Could you please explain how the trunc(hire_date) will make the difference when you used it in the to_char for getting only the day of the week.

Thanks in advance.

-Vamsee

  Was this answer useful?  Yes

Girish

  • Nov 23rd, 2006
 

select name,hiredate,to_char(hiredate,'day') from emp order by to_char(hiredate,'day') asc;

  Was this answer useful?  Yes

glakshkar

  • Sep 23rd, 2007
 

This qry won't fail :)

select data.emp_name
         ,
data.hire_date
         ,
data.day_name
  from ( select name emp_name
                    , hiredate hire_date
                    , to_char(hiredate,'day') day_name
                    , decode(to_char(hiredate,'day') , 'Monday', 1
                                                                        , 'Tuesday', 2
                                                                        , 'Wednesday',3
                                                                        , 'Thursday',4
                                                                        , 'Friday',5
                                                                        , 'Saturday',6
                                                                        , 'Sunday',7) day_no
              from emp) data
order by data.day_no;

I hav not tested this query, as i m not having oracle installed on the PC from where i m replying but this should be perfect qry [:)]

  Was this answer useful?  Yes

hemant.agarwal03

  • Feb 13th, 2008
 

It's amazing.. today I was searching something like this and got it.. thanks Hari..Divya and all Geek family members.......

Cheers...

Hemant

  Was this answer useful?  Yes

Just try this this will give you correct output.

select date_column,to_char(date_column,'dy') from table_name order by to_char(date_column,'d') desc;

This will give you the date_column and it's date in order of monday first then tue and what will come next and so on...

  Was this answer useful?  Yes

dj_dj_dj

  • Mar 22nd, 2010
 

select to_char(hire_date, 'day')
from table_name
order by to_char(hire_date -1 ,'day');




Regards
Dharmendra Jaiswal

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions