mysql - Query that returns count of values based on primary key -


i have 2 mysql tables in format student.type references type.typename

    student:     centerid | studentname | type     --------- ------------- ------     1        | abc         |     1        | def         | b     2        | ebc         |     2        | agc         |     2        | abe         | d     3        | gtc         |     3        | hic         | b      type:     typename     --------         b     c     d 

the output need in form:

    centerid | | b | c | d      --------- --- --- --- ---     1        | 1 | 1 | 0 | 0     2        | 2 | 0 | 0 | 1     3        | 1 | 1 | 0 | 0 

i have found similar problem cannot manually add each case query , when "type" changes.

count of result of sql query based on values

any kind of assistance appreciated.

select centerid,         sum(type = 'a') a,        sum(type = 'b') b,        sum(type = 'c') c,        sum(type = 'd') d student group centerid 

Comments