with t as ( select * from STSCORE a left join (SELECT CLASSNO,COURSE,round(AVG(GRADE),2) as AVG FROM STSCORE group by CLASSNO,COURSE) b on a.CLASSNO = b.CLASSNO and a.COURSE = b.COURSE) select t.CLASSNO,t.COURSE,t.AVG from t where t.CLASSNO = 'Class1' order by COURSE asc select Classno,course,ROUND(AVG(GRADE),2) from stscore where classno='Class2' group by course |