Skip to content

.net group by 时间段(年月日)

L edited this page Mar 28, 2019 · 4 revisions

按日统计

var result = (from d in yourData
		group d by new
		{
		    time = new { d.CreationTime.Year, d.CreationTime.Month, d.CreationTime.Day }
		} into g
		select new
		{
		    Value = g.Average(p => p.Value),
		    CreationTime = g.Key.time.Year + "-" + g.Key.time.Month + "-" + g.Key.time.Day
		}).ToList();

按月统计

var result = (from d in yourData
		 group d by new
		 {
		    time = new { d.CreationTime.Year, d.CreationTime.Month }
		 } into g
		 select new
		 {
		    Value = g.Average(p => p.Value),
		    CreationTime = g.Key.time.Year + "-" + g.Key.time.Month
		 }).ToList();

其他的以此类推

Clone this wiki locally