110,499
社区成员
发帖
与我相关
我的任务
分享
var stateinfo = from t in table.AsEnumerable()
group t by t.Field<string>("Name") into r
select new
{
name = r.Key.ToString(),
count = r.Count(),
illegal_count = r.Count(x => x.Field<string>("Status") == "违规")
};
Console.WriteLine("Name 总次数 违规次数 正常次数");
foreach (var result in stateinfo.OrderByDescending(g => g.illegal_count))
{
Console.WriteLine("{0,-9} {1,-9} {2,-9} {3,-9}", result.name, result.count,
result.illegal_count, result.count-result.illegal_count);
}
var list = dt.AsEnumerable().GroupBy(t => t.Field<string>("Name")).Select(t => new
{
Name=t.Key,
Sum=t.Count(),
Sum_WeiGui = t.Count(tt => tt.Field<string>("status") == "违规"),
Sum_ZhengChang = t.Count(tt => tt.Field<string>("status") == "正常")
}).ToList();
var stateinfor = from t in dt.AsEnumerable()
where t.Field<string>("status") == "违规"
group t by t.Field<string>("name") into r
orderby r.Count() descending
select new
{
name= r.Key.ToString(),
count=r.Count()
};
以上 linq 是统计违规的,其它两个 linq 就不写了,现在想通过一条linq 就把这三项值全部返回