Maybe this:select b.sname ,c.grade ,count(*) as grade_count from (select student_number from grade_report where grade in ('A','B') group by student_number having count(*)>1 ) as a inner join student as b on b.stno=a.student_number inner join grade_report as c on c.student_number=a.student_number and c.grade in ('A','B') group by b.sname ,c.grade order by b.sname ,c.grade
If you want to see only the A and B grades, remove the line marked in red.