在SQL(postgresql)中如何基于"没有时区的时间戳"列进行分组?

use*_*521 4 postgresql

我正在尝试编写一些查询来根据postgresql中的每个月对事物进行分组.

假设我们有一个表"罪行",它有2列"活动日期"(没有时区的时间戳)和"邮政编码"(字符变化(5)),如何查询给定邮政编码的每个月的犯罪数量?

例如:表"罪行":

activity date               zipcode
2014-11-22 00:52:00           12345
2014-10-22 00:52:00           12345
2014-10-24 00:52:00           12345
2014-12-22 00:52:00           54321
Run Code Online (Sandbox Code Playgroud)

输入:给定的邮编"12345"

输出:返回

month        count
2014-10        2
2014-11        1
Run Code Online (Sandbox Code Playgroud)

Jac*_*ert 6

尝试:

select
    extract(year from activity_date) as year,
    to_char(activity_date, 'Mon') as month,
    count(*) as count
from
    crimes
group by
    1,extract(month from activity_date);
Run Code Online (Sandbox Code Playgroud)