Topic: Query all students student numbers, the sum of the student's name, the total number of elective, all course grades
Analysis: see the total number should use count (course), the sum of the results should be sum (score) of these aggregate functions, because you know everyone and therefore should be people-grouping group by studentid
Because the students to know the details, so to join on student table
Write out the sql:
SELECT a.id,a.stdentname, b, c FROM student a JOIN
(SELECT studentid,COUNT(courseid)AS b,SUM(score) AS c FROM student_score GROUP BY studentid)d
ON a.id = d.studentid;
Query results: