日期:2014-05-17 浏览次数:20477 次
static void Main(string[] args)
{
DataTable dt = new DataTable();
dt.Columns.Add("lid", typeof(int));
dt.Columns.Add("uid", typeof(int));
dt.Columns.Add("ldate", typeof(DateTime));
dt.Rows.Add(1, 1, DateTime.Parse("2013-10-11"));
dt.Rows.Add(2, 1, DateTime.Parse("2013-10-12"));
dt.Rows.Add(3, 2, DateTime.Parse("2013-10-11"));
dt.Rows.Add(4, 2, DateTime.Parse("2013-10-12"));
dt.Rows.Add(5, 2, DateTime.Parse("2013-10-13"));
var result = from p in dt.AsEnumerable()
where p.Field<DateTime>("ldate") >= DateTime.Parse("2013-10-11") && p.Field<DateTime>("ldate") <= DateTime.Parse("2013-10-13")
group p by p.Field<int>("uid") into g
select new { Key = g.Key, Count = g.Count() };
result.ToList().ForEach(x => Console.WriteLine(string.Concat(x.Key, "
------解决方案--------------------
", x.Count)));