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
Post a Comment