Home Count group by enum including possible enum values that have 0 count
Reply: 0

Count group by enum including possible enum values that have 0 count

user690
1#
user690 Published in August 16, 2018, 6:16 am

I have a table of items. One of the fields is a category (represented by an enum). Some categories have zero items.

So I did this:

select category, count(*) as total from items group by category;
+------------+-------+
| category   | total |
+------------+-------+
| one        |  6675 |
+------------+-------+

I want to generate a table like this (where two is the other possible enum value):

+------------+-------+
| category   | total |
+------------+-------+
| one        |  6675 |
+------------+-------+
| two        |  0    |
+------------+-------+

How do I do this with an mysql SQL query?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309186 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO