Skip
Arish's avatar

197. Practice - Complex Grouping


Exercise: Department Stats

Stats by department and course.

Solution

sql
1SELECT d.dept_name, c.course_name,
2  COUNT(*) AS count, AVG(s.marks) AS avg
3FROM departments d
4JOIN courses c ON d.id = c.dept_id
5JOIN students s ON c.id = s.course_id
6GROUP BY d.dept_name, c.course_name;