select ROWNUM as gr_rank, name, c_rank from
(select name, avgg, ROWNUM as c_rank from
(select name, avg(grade) as avgg, count(distinct cno) as nc
from STUDENTS S, GRADES G
where S.stno = G.stno
group by S.stno,S.name
order by nc desc)
order by avgg desc)
where ROWNUM