Postgres集团数据按日计算

时间:2018-02-06 17:46:35

标签: sql postgresql

看似简单的问题,我有一个大脑冻结时刻和google-fu没有帮助。

我想获得每天特定事件类型的计数。例如:

数据:

Date Received | Type 
1-1-2017      | A
1-1-2017      | A
1-1-2017      | C
1-1-2017      | D
2-1-2017      | C
2-1-2017      | A
..

分为:

Date Received | Type | Count
1-1-2017      | A    | 2
1-1-2017      | C    | 1
1-1-2017      | D    | 1
2-1-2017      | A    | 1 

..

目前,我有一个简单的group by语句,它汇总了该行的总计数而不是分成组。有人可以帮忙吗? :)

谢谢!

1 个答案:

答案 0 :(得分:2)

这应该计算分组[Date Received][Type]的唯一实例:

SELECT "Date Received", "Type", COUNT(*) AS Count
FROM YourTable
GROUP BY "Date Received", "Type"