Linq 先 left join 再 group 再统计数量

var T_Time_Statistics = (from t in Enumerable.Range(8, 11)//早8点到晚上18点
                         join m in T_LLD_HEAD.AsEnumerable()
                         on t.ToString() equals m.Field<string>("TIME1").Substring(0, 2).TrimStart('0') into J
                         from j in J.DefaultIfEmpty()
                         group j by t into g //按时间段分组
                         orderby g.Key//按时间升序排列
                         select new
                         {
                            Time = g.Key,//时间段
                            Total = g.Where(n=>n!=null).Count(),//已流入订单to单数
                            Complete = g.Where(n => n?.Field<string>("STAT3") == "Y").Count()//仓库调度已下发给制造调度
                         }).ToList();

 

你可能感兴趣的:(Linq 先 left join 再 group 再统计数量)