【发布时间】:2021-11-10 15:04:04
【问题描述】:
在 PostgreSQL 表中,我有两列 (int8),其中包含 Unix 时间戳。 [注意:此表不是我的,所以列可以更改为实际日期,因此在查询中进行转换。]
下面是我的查询的精简版。我需要做的是按月对条目进行分组。但在我下面的查询中,2020 年 11 月的条目与 2021 年 11 月的条目分组。
select
DATE_PART('month',to_timestamp(e.startts)) as "Date", sum(e.checked)
from entries e
where
e.startts >= date_part('epoch', '2020-10-01T15:01:50.859Z'::timestamp)::int8
and e.stopts < date_part('epoch', '2021-11-08T15:01:50.859Z'::timestamp)::int8
group by "Date"
如何将“日期”作为月/年而不是月?所以例如 10/20 而不是 10。
【问题讨论】:
标签: postgresql date