mysql - How to Group and display count of each type of data? -


suppose have column has 3 types of data a, b, c. want group , count number of each type. example if 3 times in column , b 2 times , c 1 time. should display as:

a    b     c 3    2     1 

i appreciate help. thankyou.

if want data in 1 row, can use conditional aggregation:

select sum(col = 'a') a, sum(col = 'b') b, sum(col = 'c') c t; 

you can try more explicit:

select sum(case when col = 'a' 1 else 0 end) a,        sum(case when col = 'b' 1 else 0 end) b,        sum(case when col = 'c' 1 else 0 end) c t; 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -