Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order by using month name in PostgreSQL

I have a table which has a field Month_Name and it contains the names of the month. I want to ORDER BY the month names, not alphabetically, but by its actual order, like, January, February, etc. How can I implement this using PostgreSQL?

Is there any way that I can convert the Month Name to its numeric value?

id        billed_unit    billed_amount    town_id    ea_month    ea_year    
3959920   3695.17        25856.84         CHRY     April         2014
3959920   3695.17        25856.84         CHRY     August        2014
3959920   3695.17        25856.84         CHRY     February      2014
3959920   3695.17        25856.84         CHRY     July          2014
3959920   3695.17        25856.84         CHRY     June          2014
3959920   3695.17        25856.84         CHRY     March         2014
like image 463
Yousuf Sultan Avatar asked Sep 19 '14 10:09

Yousuf Sultan


1 Answers

SELECT * 
FROM EA.TOWN_CONS_BILLING_ROLLUP 
WHERE TOWN_ID='CHRY' 
      AND EA_YEAR=2014 
ORDER BY   
to_date(ea_month,'Month');

Data Type Formatting Functions

like image 169
Vivek S. Avatar answered Nov 10 '22 07:11

Vivek S.