我有表grades
:
id | student_id | grade
-----------------------
1 | 1 | 4
2 | 1 | 5
3 | 2 | 3
我想要一个返回student_id
和平均grade
的查询:
student_id | avg_grade
----------------------
1 | 4.5
2 | 3
什么查询会这样做?
答案 0 :(得分:0)
SQL AVG()
函数执行此操作:
SELECT student_id, AVG(grade) as avg_grade
FROM grades
GROUP BY student_id