I need to make a ORDER BY
in a table mes
that has the months in extenso and in Portuguese (Janeiro, Fevereiro...)
. It has no relation to any other column in the table. Is it possible to do this?
I need to make a ORDER BY
in a table mes
that has the months in extenso and in Portuguese (Janeiro, Fevereiro...)
. It has no relation to any other column in the table. Is it possible to do this?
I've been investigating and I think I've found a solution for you, passing every% of% of the month to its number (eg string
):
SELECT
CASE
WHEN mes = "Janeiro" THEN 1
WHEN mes = "Fevereiro" THEN 2
WHEN mes = "Março" THEN 3
WHEN mes = "Abril" THEN 4
...
END as meses
, mes //apresentar também o mês em string ao lado do número
FROM tbl_meses;
ORDER BY meses ASC
If this table is just to translate the months a simple solution is to add a column with month number the ordering should be done by the year and by that new column.
If you have a date field or similar and want to display the month in full in Portuguese you can set the locale in the session and sort by month.
set lc_time = 'portuguese';
select to_char(data,'tmmonth') from tabela order by extract(year from data), extract(month from data)