select year(datetime) as year,month(datetime) as month,name into #t1 from table1
select count(name) as times,month,year from #t1 group by year,month