SuperSjajan3
a sad
select student.jmbag,imestudent,prezimestudent,sifpredmet,ocjena,akgodina
from upisanpredmet as up natural join student
where akgodina=2016 and
ocjena is not null and ocjena >1 and
ocjena >= all(select ocjena
from upisanpredmet
where sifpredmet=up.sifpredmet and ocjena is not null and up.jmbag <>jmbag and akgodina=2016)
and (select avg(ocjena)
from upisanpredmet
where up.jmbag=jmbag and ocjena is not null) <4