group the data on month and sort it on date [message #385850] |
Wed, 11 February 2009 07:28  |
kashifchughtai
Messages: 125 Registered: October 2007
|
Senior Member |
|
|
hi all,
i am grouping some data on month using to_char function .
i.e to_char(Date,'MON-YY') but it sort the data on the charachter set
i want to sort the resulting data by month and year .
Dec-2008
Jan-2009
Feb-2009
so on
is there any way to do it?
thanks
|
|
|
|
|
|
|
Re: group the data on month and sort it on date [message #385937 is a reply to message #385856] |
Wed, 11 February 2009 23:33  |
kashifchughtai
Messages: 125 Registered: October 2007
|
Senior Member |
|
|
Sorry i guess my question was not so clear thats why you people are having differnnt interpretations.
Anyway thanks for the help. this one working fine...
select count(*), to_char(trunc(date_column, 'MM'), 'MON-YY')
from my_table
group by trunc(date_column, 'MM')
order by trunc(date_column, 'MM');
i have found another way.
select count(*), to_char(date_column, 'MON-YY')
from my_table
group by to_char(date_column, 'MON-YY'),to_char(date_column, 'YYYYMM')
order by to_char(date_column, 'YYYYMM') ;
[Updated on: Wed, 11 February 2009 23:33] Report message to a moderator
|
|
|