Reputation: 55
I have a mysql table that looks like this:
Date Status
2020-03-27 true
2020-03-27 true
2020-03-28 false
2020-03-28 true
How can I count the booleans and get a result like this:
Date Success Failed
2020-03-27 2 0
2020-03-28 1 1
Upvotes: 1
Views: 474
Reputation: 1270011
You can use:
select date, sum(status) as success, sum(not status) as failed
from t
group by date;
MySQL treats boolean "true" as "1" and boolean false as "0", so sum()
works on them.
Upvotes: 1