select month=convert(varchar(6),Addtime,112),monthcount=count(*) from NewsContent group by convert(varchar(6),Addtime,112) order by month
sql语句执行结果:
201105 22 201106 1 201111 6 201203 1 201204 2
------解决方案-------------------- var query=from u in dt.AsEnumerable().Where(c=>c.Field<DateTime?>("ShippedDate")!=(DateTime?)null) group u by new {mouth=u.Field<DateTime>("ShippedDate").Year.ToString() +u.Field<DateTime>("ShippedDate").Month} into g select new { g.Key, count= g.Count() };
------解决方案--------------------