首页 > 解决方案 > PostgreSQL 按月份名称排序

问题描述

我有这个查询

SELECT DISTINCT ON (tours.departure.departure_month)
                   tours.departure.departure_month
FROM tours.departure

但我想按月份名称订购不同的月份。我已经从一个类似的问题中尝试过这个to_date(tours.departure.departure_month, 'Month'),但我无法使用它DISTINCT ON

标签: postgresql

解决方案


什么是department_month的列类型是日期或月份名称,如果它的日期类型列您可以尝试以下操作:

SELECT DISTINCT ON (tours.departure.departure_month)
       tours.departure.departure_month
FROM tours.departure
ORDER BY month(tours.departure.departure_month) DESC;

推荐阅读