Order By Issue.... [message #204588] |
Tue, 21 November 2006 06:06 |
sundarsoft
Messages: 15 Registered: October 2006
|
Junior Member |
|
|
Hi
I am having query like this
select to_char(create_date,'Mon,yyyy'),sum(test)
from test1
group by to_char(create_date,'Mon,yyyy')
order by to_char(create_date,'Mon,yyyy')
I am getting results correct..
but orderby is consdered as STRING not by DATE
but i have order records by date
Plz help mee
Sundar
|
|
|
|
Re: Order By Issue.... [message #204608 is a reply to message #204597] |
Tue, 21 November 2006 06:33 |
sundarsoft
Messages: 15 Registered: October 2006
|
Junior Member |
|
|
select to_char(mo.request_date,'Mon,yyyy') month,sum(mod.ordered_quantity) ordered
from material_order mo,material_order_detail mod
where mo.material_order_id = mod.material_order_id
and mo.request_date >= to_date('Aug,2005','Mon,yyyy')
group by to_char(mo.request_date,'Mon,yyyy')
order by to_char(mo.request_date,'Mon,yyyy')
here o/p is
-----------
Apr,2006 1
Aug,2005 2
.
.
.
But o/p must be
Aug,2005 2
Apr,2006 1
Order by is done based on string
but not on date
|
|
|
|
|
|
|
|
|
Re: Order By Issue.... [message #204631 is a reply to message #204625] |
Tue, 21 November 2006 07:49 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
An example: group by TO_CHAR, order by TO_DATE(TO_CHAR); it *seems* that records are correctly ordered.SELECT TO_CHAR(hiredate, 'mon, yyyy') mon_yyyy, SUM(sal) sal
FROM EMP
GROUP BY TO_CHAR(hiredate, 'mon, yyyy')
ORDER BY TO_DATE(TO_CHAR(hiredate, 'mon, yyyy'), 'mon, yyyy')
|
|
|