如何在Linq中执行followimg查询 [英] How to perform followimg query in Linq
问题描述
已完成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
推荐答案
嗨 ArfatM,
>>在数据库中,用户ID 1022已完成2个单位(id:100和101)用户id 1021完成3个单位(id:100,101,102)如果我通过userid(1022)courseid(109)semid(3000)subjectid(2006)然后结果是
平均是scoredmarks / totalmarks * 100即77.5 User1022的排名为1,用户1021的排名为2
问题是什么你见过了吗? 我已经测试了我这方面的代码。它可以得到结果"平均值是得分标记/总标记* 100是77.5,用户1022的排名是1,用户1021排名将是2"。$
此外,为了您的描述,我建议您转到
数据平台开发论坛提供合适的帮助。
Hi ArfatM,
>> in database userid 1022 has completed 2 units( id:100 and 101) user id 1021 completed 3 units (id:100,101,102) if i pass userid (1022)courseid(109) semid(3000) subjectid(2006) then result shoild be average is scoredmarks/totalmarks * 100 that is 77.5 and rank of User1022 is 1 and user 1021 rank will be 2
what's the problem you have met? I have test the code on my side. It can get the result "average is scoredmarks/totalmarks * 100 that is 77.5 and rank of User1022 is 1 and user 1021 rank will be 2".
Besides, for your description, I suggest you go to the Data Platform Development forum for getting suitable help.
最好的问候,
Yong Lu
Best Regards,
Yong Lu
这篇关于如何在Linq中执行followimg查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!