select c.student_id,c.student_name,m.学年,m.成绩 from student c inner join
(select b.student_id,datepart(year,b.attend_date) 学年,sum(c.attend_grade) as 成绩 from attend a inner join student_attend b
on a.attend_id=b.attend_id group by b.student_id,datepart(year,b.attend_date)) m
on c.student_id=m.student_id