I'm trying to count latest actions from devices in my table:
| device | action | timestamp |
|---|---|---|
| 1 | running | 2022-09-12 16:20:10 |
| 1 | shutdown | 2022-09-10 16:20:10 |
| 2 | running | 2022-09-12 16:20:10 |
| 2 | starting | 2022-09-11 16:20:10 |
| 3 | starting | 2022-09-11 16:20:10 |
I'm trying :
SELECT
count(device)
FROM
table
WHERE
action='shutdown'
AND
timestamp=(SELECT max(timestamp) FROM table)
;
But can't get it to work. Expected result :
- when querying
shutdown: 0 - when querying
running: 2 - when querying
starting: 1
All I get is the full count of the actions.