表test
name value
zhang A
zhang B
zhang A
zhang C
li A
li A
li B
wang B
wang B
wang C
lei A
lei B
結果
name value num
zhang A 2
zhang B 1
zhang C 1
li A 2
li B 1
wang B 2
wang C 1
lei A 1
lei B 1
select t.name,t.value count(t.name) num from table test t
group by t.name,t.value;