How to use order by stop ordering month names in Oracle

Asked

Viewed 118 times

2

Hello, I would like to know how to solve this problem. I would like to take the name of the days of the month and sort them and not the numbers of the corresponding months. Follow the query I performed but ordered only in numbers corresponding to the months.

SELECT to_char(hsp_checkin, 'month') as "Mês", 
       count(hsp_id) as "Total de Hospedagens" 
FROM HOSPEDAGENS
GROUP BY to_char(hsp_checkin, 'month');

Small correction in the description of the question. "I would like to take the name of the days of the month" actually is: I would like to take the name of the months.

  • 2

    ORDER BY 1 does not solve?

  • In case you want to sort by counting "Total Accommodation"?

  • Order by 1 does not solve it. I want to sort by the name of the months and not by the numbers that represent them. Ex: January, February, March, and no, April, August...

1 answer

1

As commented on the question, you should add the clause order by:

SELECT to_char(hsp_checkin, 'month') as "Mês", 
   count(hsp_id) as "Total de Hospedagens" 
FROM HOSPEDAGENS
GROUP BY to_char(hsp_checkin, 'month')
ORDER BY 1; -- to_char(hsp_checkin, 'month')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.