我正在尝试写linq查询:
SQL:
select s.s_name, sum(sub.evaluation) as suma from submit_task sub
join student s on s.id=sub.student_id
join study_group g on g.id=s.study_group_id
where g.g_name="abcd"
group by s.s_name
order by suma desc
答案 0 :(得分:3)
看看这篇文章。 http://www.codeproject.com/Articles/35667/How-to-Use-LINQ-GroupBy 1
作者描述的内容与您所要求的内容相近
答案 1 :(得分:0)
var groupName = "abcd";
var query =
from submitTask in db.submit_task
join student in db.student
on submitTask.student_id equals student.id
join studyGroup in db.study_group
on student.study_group_id equals studyGroup.id
where studyGroup.g_name == groupName
group submitTask by student.s_name into g
let suma = g.Sum(st => st.evaluation)
orderby suma descending
select new
{
s_name = g.Key,
suma = suma,
};