Mithun
Mithun

Reputation: 31

SQL - Finding Highest average marks of the students

I am trying to display the maximum average marks; however, I can't seem to get it to work.

I can get the average marks to display using:

select max(avg_mark)
from (select round(avg(value),2) as avg_mark from mark;

Schema diagram for reference

The output I am getting = 82.73

Expected Output = 85.67

I am not sure where I am going wrong, am I supposed to round the max(avg_mark) like shown below

select round(max(avg_mark),2)
from (select avg(value) as avg_mark from mark;

Upvotes: 1

Views: 1503

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1269753

Your code would work with the right subquery:

select max(avg_mark)
from (select round(avg(value), 2) as avg_mark
      from mark
      group by student_id
     ) sm;

I am not a fan of Oracle's nested aggregation functions -- it is non-standard and not adopted by any other database.

Upvotes: 0

Mithun
Mithun

Reputation: 31

UPDATED POST:

WORKING ANSWER:

Alright got it working. It doesn't need too much hassle

select round(max(avg(value)),2) as avg_mark from mark group by student_id;

Round function to specify decimal place.

Upvotes: 1

Related Questions