排名
3
文章
317
粉丝
22
评论
14
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术

两表分组与函数
例如:对某个考生的成绩统计
linq形式:
- var query = from u in oae.Users
- join s in oae.Score on u.Id equals s.UsersId
- select new
- {
- UserName = u.UserName,
- Score1 = s.Score1
- } into jointemp
- group jointemp by jointemp.UserName into a
- select new ScoreViewModel
- {
- UserName = a.Key,
- Count = a.Count(),
- Max = a.Max(b => b.Score1),
- Min = a.Min(b => b.Score1),
- Sum = a.Sum(b => b.Score1),
- Avg = a.Average(b => b.Score1)
- };
- List<ScoreViewModel> result = query.ToList();
三表分组与函数,多字段分组
例如:对某个考生的成绩统计,并包含考生父母
linq形式:
- var query = from u in oae.Users
- join p in oae.User_Parent on u.Id equals p.UsersId into upjointemp
- from leftjoin in upjointemp.DefaultIfEmpty()
- join s in oae.Score on u.Id equals s.UsersId
- select new
- {
- UserName = u.UserName,
- Father = leftjoin.Father,
- Score1 = s.Score1
- } into jointemp
- group jointemp by new { jointemp.UserName, jointemp.Father } into a
- select new ScoreViewModel
- {
- UserName = a.Key.UserName,
- Father = a.Key.Father ?? "孤儿",
- Count = a.Count(),
- Max = a.Max(b => b.Score1),
- Min = a.Min(b => b.Score1),
- Sum = a.Sum(b => b.Score1),
- Avg = a.Average(b => b.Score1)
- };
- List<ScoreViewModel> result = query.ToList();
欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739。有需要软件开发,或者学习软件技术的朋友可以和我联系~(Q:815170684)
评价