linq按条件sum

var result = fruit.GroupBy(i => i.date)
            .Select(i => new
            {
                date = i.Key,
                no_of_apple = i.Where(j => j.fruit_code == "apple").Sum(k => k.count),
                no_of_pear = i.Where(j => j.fruit_code == "pear").Sum(k => k.count)
            });
posted @ 2016-07-10 08:09  shiningrise  阅读(1859)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css