Wboy
Wboy

Reputation: 2552

Postgres Group Data into Counts by Day

Seemingly simple problem which I'm having a brain freeze moment and google-fu isn't helping.

I want to get the counts of the type of a certain event per day. eg:

Data:

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
..

Into:

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

..

Currently I've got a simple group by statement which aggregates the total counts of that row instead of separating into groups. Could anyone help? :)

Thank you!

Upvotes: 0

Views: 53

Answers (1)

Jacob H
Jacob H

Reputation: 2515

This should count the unique instances of the grouping [Date Received] and [Type]:

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

Upvotes: 2

Related Questions