Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Sorting Problem in Month and Year in SQL

Kam__apexAug 27 2021

Hi Friends,
Below is a query and I am facing difficulty to make them order by month and year. Means July 2020 should come first then Aug 2020 and so on. Please help.
select to_CHAR(b.doc_date,'RRRR-MON'),sum(a.weight*b.quantity)/1000 from trstock.items a,production.prodmld b
where a.item_Code = b.item_code
and b.doc_date between '01/07/2020' and '31/07/2021'
and a.item_class = 'GI'
group by to_CHAR(b.doc_date,'RRRR-MON')
ORDER BY to_CHAR(b.doc_date,'RRRR-MON');
Result
2020-AUG 580.01209
2020-DEC 843.27038
2020-JUL 657.47221
2020-NOV 763.77242
2020-OCT 950.31912
2020-SEP 868.72952
2021-APR 885.7445
2021-FEB 857.94809
2021-JAN 705.83493
2021-JUL 743.3809
2021-JUN 877.91936
2021-MAR 791.49349
2021-MAY 778.53311
Regards
Kam

This post has been answered by Kam__apex on Aug 27 2021
Jump to Answer
Comments
Post Details
Added on Aug 27 2021
4 comments
3,608 views