[Sql: Exercise 4] to query all students student number, student name the total score, total enrollment, all courses

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:

 

Guess you like

Origin www.cnblogs.com/yuanyuan2017/p/11323167.html