How to count how many items for distinct items in mysql?

Posted by Vincent Duprez on Stack Overflow See other posts from Stack Overflow or by Vincent Duprez
Published on 2013-10-27T21:49:23Z Indexed on 2013/10/27 21:53 UTC
Read the original article Hit count: 169

Filed under:
|

Imagine a have a table with a column named status:

status
------
A
A
A
B
C
C
D
D
D

How can I count how many rows have A, how many rows have B etc? this kind of output:

A  |B  |C  |D  |E  
------------------
3  |1  |2  |3  |0

As for E = O , this will always be A,B,C,D and E Output should be one row (thus 1 query).

When doing a distinct count (most returning answer on my searches, it does return how many different elements there are, 4 in this case...)

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql