I have a table with following sample output;
Act_ID | STATUS | Year-Month
123 | a | 2020-Dec
120 | a | 2020-May
124 | b | 2021-Feb
Is it possible to order it as per time; we want the following output;
Desired Output
Act_ID | STATUS | Year-Month
120 | a | 2020-May
123 | a | 2020-Dec
124 | b | 2021-Feb
But when we try to order by this column, it is sorting it alphabetically.
SELECT *
FROM table
ORDER BY Year-Month;
Actual Output
Act_ID | STATUS | Year-Month
123 | a | 2020-Dec
124 | b | 2021-Feb
120 | a | 2020-May
Convert the value to a date:
order by to_date(year_month, 'YYYY-MON')
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.