I am trying to create a query which - when executed - will show a date, status (where there are there are several status options) and the number of events on that date - distinguished by status.
I was able to create a query which shows all data I desire, but I am getting repetitions in dates. I think the way to do it is to use the aliases, but I can't figure out the way. I also tried the case statement, but with no success neither.
SELECT cast(event_date AS date) AS date, count(event_status) AS amount, status
FROM events
GROUP BY date, status
Right now this is what I'm getting:
date | amount | status
---------------------------------------
2019-05-07 | 5 | YES
2019-05-07 | 1 | NO
2019-05-06 | 4 | YES
2019-05-05 | 3 | YES
2019-05-04 | 6 | YES
2019-05-04 | 2 | MAYBE
And this is what I want to get:
date | POSITVE | Negative
---------------------------------------
2019-05-07 | 5 | 1
2019-05-06 | 4 | 0
2019-05-05 | 3 | 0
2019-05-04 | 6 | 2
where any status which isnt't equal to 'Yes' is negative. Any suggestions? Just to clarify: my desired output is just one of the options, I know there could be different ways to solve my problem, but this will suit me fine. Thanks