with ispitBr as (select indeks
from ispit 
where ocena>5 and status_prijave='o'
group by indeks
having count(*)=10)
select d.indeks, ime, prezime, s.naziv, p.naziv, i.ocena
from dosije d join ispitBr ibr on d.indeks=ibr.indeks
	join smer s on d.id_smera=s.id_smera
	join ispit i on d.indeks=i.indeks and ocena>5 and status_prijave='o'
	join predmet p on i.id_predmeta=p.id_predmeta
order by d.indeks, ime, prezime, s.naziv, p.naziv
;

