如果第二个表中有第一个表中所有的数据的话,只要
Select id, name, count(*) as IDCount from table2 group by id, name 即可。
如果第二个表可能缺失某些数据,而希望在第三个表中表达为0(计算字段),则
Select table1.id, table1.name, ifnull(IDCount, 0) as IDCount from table1 m
left outer join (Select id, name, count(*) as IDCount from table2 group by id, name)N
on M.id=N.id