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)
            });

你可能感兴趣的:(linq按条件sum)