By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
month | dog | cat |
---|---|---|
2019-06 | 1 | 2 |
2019-07 | 1 | 2 |
2019-08 | 0 | 3 |
2019-09 | 0 | 3 |
@sql |
---|
Sum(`animal` = 'cat') as `cat`,Sum(`animal` = 'dog') as `dog` |
@sql |
---|
SELECT date_format(`timestamp`, "%Y-%m") `month`, Sum(`animal` = 'cat') as `cat`,Sum(`animal` = 'dog') as `dog` from `animals` group by `month` order by `month` |
month | cat | dog |
---|---|---|
2019-06 | 2 | 1 |
2019-07 | 2 | 1 |
2019-08 | 3 | 0 |
2019-09 | 3 | 0 |