C# Lambda Left Join AND Group by Then Sum

            var list = List1.Join(
                                        List2,
                                        l1 => new { l1.Cityid },
                                        l2 => new { l2.Cityid },
                                        (item1, item2) => new
                                        {
                                            Report_date = item1.Rdate,
                                            Cityname = item2.Cityname,
                                            Th = item1.Th,
                                            Yh=item1.Yh,
                                            Eh= item1.Eh,
                                        }) //2列表left jion
                                  .GroupBy(p => new { p.Report_date, p.Cityname })
                                  .Select(g => new
                                  {
                                      Cityname = g.Key.Cityname,
                                      Report_date = g.Key.Rdate,
                                      DH = g.Sum(t => t.Th) + g.Sum(t => t.Yh) + g.Sum(t=>t.Eh)
                                  }).ToList();//分组计算

posted @ 2019-09-29 16:12  TTonlyV5  阅读(603)  评论(0编辑  收藏  举报