2013-05-05 79 views
-1

我試圖寫LINQ查詢組:通過LINQ to SQL中

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
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, 
    }; 
+0

謝謝你,這麼多,它的工作 – Patrik18 2013-05-05 23:54:42