I'm trying to figure out how I can group the SQL results from a table in Oracle in the actual order in which the month occurred instead of the alphabet order of their names.
Can anyone help me with this? Thanks in advanced.
Here's an example query:
SELECT exec_month FROM table_or_view WHERE condition=1 GROUP BY exec_month;
You see, the problem is that I can't group by month like I want to. Just as Vincent Malgrat said, "Grouping has no implied order".
Grouping has no implied order . Add an ORDER BY clause if you want to display the rows in a certain order:
SQL> with data as (
2 SELECT add_months(trunc(sysdate, 'year'), rownum-1) dt
3 FROM dual CONNECT BY LEVEL <= 4
4 )
5 select to_char(dt, 'month')
6 from data
7 group by to_char(dt, 'month'), trunc(dt, 'month')
8 order by trunc(dt, 'month');
TO_CHAR(D
---------
january
february
march
april
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.