排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术
分类:
EF
单表分组函数
linq写法:
//linq var query = from score in oae.Score group score by score.Sub into grouptemp select new { sub = grouptemp.Key, sum = grouptemp.Sum(a => a.Score1), max = grouptemp.Max(a => a.Score1), min = grouptemp.Min(a => a.Score1), avg = grouptemp.Average(a => a.Score1) };
lamdba写法:
//lamdba var query = oae.Score.GroupBy(a => a.Sub).Select(grouptemp => new { sub = grouptemp.Key, sum = grouptemp.Sum(a => a.Score1), max = grouptemp.Max(a => a.Score1), min = grouptemp.Min(a => a.Score1), avg = grouptemp.Average(a => a.Score1) }).Where(a => a.max > 60); var result = query.ToList();
分组函数后接一点条件
linq写法:
//linq var query = from score in oae.Score group score by score.Sub into grouptemp where grouptemp.Sum(a=>a.Score1)>60 select new { sub = grouptemp.Key, sum = grouptemp.Sum(a => a.Score1), max = grouptemp.Max(a => a.Score1), min = grouptemp.Min(a => a.Score1), avg = grouptemp.Average(a => a.Score1) };
linq写法2:
//linq var query = from score in oae.Score group score by score.Sub into grouptemp select new { sub = grouptemp.Key, sum = grouptemp.Sum(a => a.Score1), max = grouptemp.Max(a => a.Score1), min = grouptemp.Min(a => a.Score1), avg = grouptemp.Average(a => a.Score1) } into temp where temp.max > 60 select new { sub = temp.sub, sum = temp.sum }; var result = query.ToList();
欢迎加群讨论技术,群:677373950(满了,可以加,但通过不了),2群:656732739
评价