Rešiti na relacionoj algebri i računu:
Primer 1: Pronaći indekse studenata koji su predmet sa identifikatorom 4002 polagali tačno dva puta.
relaciona algebra
define alias i1 for ispit
define alias i2 for ispit
define alias i3 for ispit
((i1 times i2) where i1.indeks=i2.indeks and i1.id_predmeta=4002 and
i2.id_predmeta=4002 and i1.datum_ispita<>i2.datum_ispita)[i1.indeks]
minus
((i1 times i2 times i3) where i1.indeks=i2.indeks and i1.indeks=i3.indeks and
i1.id_predmeta=4002 and i2.id_predmeta=4002 and i3.id_predmeta=4002 and
i1.datum_ispita<>i2.datum_ispita and i1.datum_ispita<>i3.datum_ispita and
i2.datum_ispita<>i3.datum_ispita )[i1.indeks]
relacioni račun
range of dx is dosije
range of ix,iy,iz is ispit
dx.indeks
where exists ix(ix.indeks=dx.indeks and ix.id_predmeta=4002 and exists iy(
iy.indeks=dx.indeks and iy.id_predmeta=4002 and ix.datum_ispita<>iy.datum_ispita
and not exists iz(iz.indeks=dx.indeks and iz.id_predmeta=4002 and
ix.datum_ispita<>iz.datum_ispita and iy.datum_ispita<>iz.datum_ispita)))
Primer 2: Pronaći predmete koje su položili dva studenta rođena istog dana. Izdvojiti datum rođenja i naziv predmeta.
relaciona algebra
define alias ispit1 for ispit
define alias dosije1 for dosije
(((ispit where ocena>5) join dosije) times ((ispit1 where ocena>5) join dosije1))
where ispit.id_predmeta=ispit1.id_predmeta and ispit.indeks<ispit1.indeks
and dosije.datum_rodjenja=dosije1.datum_rodjenja)[ispit.id_predmeta, dosije.datum_rodjenja]
join predmet)[datum_rodjenja, naziv]
relacioni račun
range of px is predmet
range of dx, dy is dosije
range of ix, iy is ispit
dx.datum_rodjenja, px.naziv
where exists ix(ix.indeks=dx.indeks and ix.id_predmeta=px.id_predmeta and ix.ocena>5 and
exists iy(iy.id_predmeta=px.id_predmeta and iy.ocena>5 and exists dy(dy.indeks<>dx.indeks
and dx.datum_rodjenja=dy.datum_rodjenja)))
Primer 3: Pronaći indeks studenta koji
relaciona algebra
(ispit where ocena>5)[indeks, id_predmeta]
divideby
(predmet where bodovi=6)[id_predmeta]
relacioni račun
range of px is predmet
range of dx is dosije
range of ix is ispit
dx.indeks
where forall px( if px.bodovi=6 then exists ix(ix.indeks=dx.indeks and
ix.id_predmeta=px.id_predmeta and ix.ocena>5))
relaciona algebra
((ispit where ocena>5) join (predmet where bodovi=6)[id_predmeta])[indeks]
minus
((ispit where ocena>5)[indeks, id_predmeta]
divideby
(predmet where bodovi=6)[id_predmeta])
relacioni račun
range of px, py is predmet
range of dx is dosije
range of ix, iy is ispit
dx.indeks
where exists px(px.bodovi=6 and not exists ix(ix.indeks=dx.indeks and
ix.id_predmeta=px.id_predmeta and ix.ocena>5))
and exists py(py.bodovi=6 and exists iy(iy.indeks=dx.indeks and
iy.id_predmeta=py.id_predmeta and iy.ocena>5))
relaciona algebra
dosije[indeks]
minus
((ispit where ocena>5)[indeks, id_predmeta]
divideby
(predmet where bodovi=6)[id_predmeta])
relacioni račun
range of px, py is predmet
range of dx is dosije
range of ix, iy is ispit
dx.indeks
where exists px(px.bodovi=6 and not exists ix(ix.indeks=dx.indeks and
ix.id_predmeta=px.id_predmeta and ix.ocena>5))