postgresql - PostgreSQL 按月份名称排序
问题描述
我有这个查询
SELECT DISTINCT ON (tours.departure.departure_month)
tours.departure.departure_month
FROM tours.departure
但我想按月份名称订购不同的月份。我已经从一个类似的问题中尝试过这个to_date(tours.departure.departure_month, 'Month')
,但我无法使用它DISTINCT ON
。
解决方案
什么是department_month的列类型是日期或月份名称,如果它的日期类型列您可以尝试以下操作:
SELECT DISTINCT ON (tours.departure.departure_month)
tours.departure.departure_month
FROM tours.departure
ORDER BY month(tours.departure.departure_month) DESC;
推荐阅读
- python - 无法使用 Django 连接到 mysql 数据库
- java - spring cloud gateway中如何转发客户端证书?
- shell - 将文件的列复制到另一个管道分隔文件的特定位置
- flutter - 无法使用来自 Future 函数中的参数的数据
- c# - 如何显示 Rest API 的错误信息?
- pandas - 如何在 pandas DataFrame 上执行滚动窗口,每行包含不应替换的 nan 值?
- node.js - 使用 Node.js 遍历文件系统的问题
- asp.net-core - 重构自定义 ProblemDetailsFactory
- python - 为什么 .isascii() 在 google colab 上不起作用?
- c# - 使用显式网络凭据从 .Net Core API 调用启用 SSO 的 API