本文介绍了如何在Linq中执行followimg查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
已完成2个单位(id :100和101)用户ID 1021完成3个单位(id:100,101,102)如果我通过userid(1022)courseid(109)semid(3000)
subjectid(2006)然后结果shoild是scoredmarks / totalmarks * 100即77.5,User1022的排名为1,用户1021排名为b 2
public GetCalculatePerform(int? Student_ID, int? CourseID, int? SemID, int? SubjectID)
{
var scoreCard = dbcontext.Stu_Result
.Where(u => u.CourseID == CourseID && u.SemID == SemID && u.SubjectID == SubjectID);
return scoreCard.GroupBy(u => u.UserID).OrderByDescending(g => g.Average(u => u.ScoredMarks / u.TotalMarks * 100)).Select
((g, i) => new UserRankObject
{
UserId = (int)g.Key,
Rank = i + 1,
AverageScore = g.Average(u => u.ScoredMarks / u.TotalMarks * 100)
}).Single(u => u.UserId == Student_ID);
}
RID UserID CourseID SemID SubjectID UnitID ScoredMarks TotalMarks No_Attempts CreatedDate ModifiedDate
1 1021 109 3000 2006 100 30 100 1 2019-02-12 00:00:00.000 NULL
2 1021 109 3000 2006 101 40 100 1 2019-02-18 00:00:00.000 NULL
3 1021 109 3000 2006 102 85 100 1 2019-02-19 00:00:00.000 NULL
4 1022 109 3000 2006 101 80 100 1 2019-02-19 00:00:00.000 NULL
5 1022 109 3000 2006 100 75 100 1 2019-02-19 00:00:00.000 NULL
推荐答案
最好的问候,
Yong Lu
Best Regards,
Yong Lu
这篇关于如何在Linq中执行followimg查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!