Ordering the retrieved dates from Database
I am retrieving the data from Oracle using JDBC API. I want to get the last 24 months starting from current month and the respective count of records.
I wrote the query as shown below:
(TIMESTAMP is of Data type DATE)
SELECT MONTH_YEAR,SUM(MONTH_COUNT) FROM
(SELECT
REPLACE(TO_CHAR(TIMESTAMP,'MON-YYYY'),'-','_') AS MONTH_YEAR, 1 AS MONTH_COUNT
FROM
MASTER
WHERE
TIMESTAMP >= TRUNC((ADD_MONTHS(SYSDATE, -24)),'MM'))
GROUP BY MONTH_YEAR
However, i cannot order by MONTH_YEAR as that will be ordered by alphabets(A,B,C..) as MONTH_YEAR is a string.
What i would appreciate is if anyone could point me how to order the result by date either on the DB query or on the Java end.
Thanks in advance!
|