Getting the above average student from database

后端 未结 5 1360
别跟我提以往
别跟我提以往 2021-01-15 18:40

I\'ve created a view that contains:

 student_full_name    subject_code    result
 Jennifer Higgins     CS1234          81
 Jennifer Higgins     CS1235                


        
5条回答
  •  天命终不由人
    2021-01-15 19:35

    This should do the job. First inner query will give you the result of average of all students. While second will give the avg for the table.

        SELECT student_full_name 
        FROM (SELECT student_full_name,
                     AVG(results) AS average_Sresult
              FROM viewEnrol
              GROUP BY student_full_name) sre, 
             (SELECT (AVG(results)) tavg
              FROM viewEnrol) ta
         WHERE sre.average_Sresult > ta.tavg
    

    PS: Should not you take the avg of avg rather than taking the avg of all results.

提交回复
热议问题