Getting the above average student from database

后端 未结 5 1319
别跟我提以往
别跟我提以往 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:33

    Getting the average result should just be a matter of filtering, so you shouldn't need to reference the outer query when calculating the global average. Your pseudo code is very close to what you need. You probably want to convert the where clause to a having clause. You also seem to be after comparing students that are above average students - not students who are performing above the net average. Make sure you're perfectly clear on what the definition of average is.

    Something on this form:

    select student_full_name, avg(results) as avg_result
    from viewEnrol
    group by student_full_name
    having avg(results) > (
        select avg(avg_results)
        from (
            select name, avg(results) as avg_results
            group by student_full_name
            )
        )
    

提交回复
热议问题