I have a table with these three columns (plus some others that are not relevant):

connector_pk, group_status and status_timestamp

There are 3 different types of group_status and the connector_pk can be any one of them, but only one at a time. I would like to count the number of connector_pks for each group_status based on their latest status_timestamp.

Example table

connector_pk    group_status    status timestamp
1               Available       2020-02-11 19:14:45
1               Charging        2020-02-11 19:18:45
2               Available       2020-02-11 19:15:45
2               Not Available   2020-02-11 19:18:45
3               Not Available   2020-02-11 19:14:45

The desired output would look like this:

group_Status      | Count of status    
Available         | 0    
Charging          | 1    
Not Available     | 2

I have used the following code, but it doesn't provide a count for each connector_pk or create a new table:

select group_status, count(group_status)
   from connector_status_report
   where status_timestamp in (
select  max(status_timestamp)
from connector_status_report
)
group by group_status
0

There are 0 best solutions below