Tabela DOSIJE
INDEKS | IME | PREZIME | DATUM_RODJENJA | MESTO_RODJENJA | DATUM_UPISA |
---|
Tabela PREDMET
ID_PREDMETA | SIFRA | NAZIV | BODOVI |
---|
Tabela ISPITNI_ROK
GODINA_ROKA | OZNAKA_ROKA | NAZIV |
---|
Tabela ISPIT
INDEKS | ID_PREDMETA | GODINA_ROKA | OZNAKA_ROKA | OCENA | DATUM_ISPITA | BODOVI |
---|
Rešiti na relacionom računu
Primer 1: Prikazati šifru i naziv predmeta.
range of px is predmet
px.sifra, px.naziv
Primer 2: Prikazati podatke o predmetima koji imaju po 6 bodova.
range of px is predmet
px.id_predmeta, px.sifra, px.naziv, px.bodovi
where px.bodovi=6
ili
px.*
where px.bodovi=6
Primer 3: Izdvojiti ime i prezime studenta sa indeksom 25/2014.
range of dx is dosije
dx.ime, dx.prezime
where indeks=20140025
Primer 4: Za svakog studenta izdvojiti predmete koje je polagao. Izdvojiti indeks studenta, naziv predmeta i ocenu koju je dobio.
range of px is predmet
range of ix is ispit
ix.indeks, ix.ocena, px.naziv
where ix.id_predmeta=px.id_predmeta
Primer 5: Izdvojiti parove predmeta koji imaju isti broj bodova. Izdvojiti šifre i nazive predmeta.
range of px, py is predmet
px.sifra, px.naziv, py.sifra, py.naziv
where px.id_predmeta<py.id_predmeta and px.bodovi=py.bodovi
Primer 6: Izdvojiti šifre i nazive predmeta koje je položio student sa indeksom 26/2014.
range of px is predmet
range of ix is ispit
px.sifra, px.naziv
where exists ix(ix.id_predmeta=px.id_predmeta and ix.indeks=20140026 and ix.ocena>5)
Primer 7: Izdvojiti indekse studenata koji su polagali sve predmete.
range of dx is dosije
range of px is predmet
range of ix is ispit
dx.indeks
where forall px(exists ix(ix.indeks=dx.indeks and ix.id_predmeta=px.id_predmeta))
ili
dx.indeks
where not exists px( not exists ix(ix.indeks=dx.indeks and ix.id_predmeta=px.id_predmeta))
Primer 8: Izdvojiti nazive predmeta koji imaju po 6 bodova i koje je polagao student sa prezimenom Vukovic.
range of dx is dosije
range of ix is ispit
range of px is predmet
px.naziv
where bodovi=6 and exists ix(ix.id_predmeta=px.id_predmeta and exists dx( dx.indeks=ix.indeks and dx.prezime='Vukovic'))
Primer 9: Izdvojiti indekse studenata koji su položili bar sve predmete koje je položio student sa indeksom 25/2014.
range of dx is dosije
range of ix, iy is ispit
range of px is predmet
dx.indeks
where forall px( if exists ix(ix.id_predmeta=px.id_predmeta and ix.indeks=20140025 and ix.ocena > 5)
then exists iy(iy.id_predmeta=px.id_predmeta and iy.indeks=dx.indeks and iy.ocena >5))
ili
range of dx is dosije
range of ix, iy is ispit
range of px is predmet
dx.indeks
where forall px( not exists ix(ix.id_predmeta=px.id_predmeta and ix.indeks=20140025 and ix.ocena > 5)
or exists iy(iy.id_predmeta=px.id_predmeta and iy.indeks=dx.indeks and iy.ocena >5))
ili
range of dx is dosije
range of ix, iy is ispit
range of px is predmet
dx.indeks
where not exists px( exists ix(ix.id_predmeta=px.id_predmeta and ix.indeks=20140025 and ix.ocena > 5)
and not exists iy(iy.id_predmeta=px.id_predmeta and iy.indeks=dx.indeks and iy.ocena >5))
ili
range of ix, iy, iz is ispit
ix.indeks
where forall iy( if iy.indeks=20140025 and iy.ocena>5 then
exists iz( iz.indeks=ix.indeks and iz.id_predmeta=iy.id_predmeta and iz.ocena>5))
Primer 10:Izdvojiti indeks, ime i prezime studenta koji je položio samo Programiranje 1.
range of dx is dosije
range of ix, iy is ispit
range of px is predmet
dx.indeks, dx.ime, dx.prezime
where exists ix(ix.indeks=dx.indeks and ix.ocena>5 and
exists px(px.id_predmeta=ix.id_predmeta and px.naziv='Programiranje 1' and
not exists iy(iy.indeks=dx.indeks and iy.id_predmeta<>px.id_predmeta and iy.ocena>5)))
Rešiti na relacionoj algebri i relacionom računu
Primer 11: Pronaći predmet sa najvećim brojem bodova. Izdvojiti naziv i broj bodova predmeta.
relaciona algebra
DEFINE ALIAS P1 FOR PREDMET
DEFINE ALIAS P2 FOR PREDMET
PREDMET[NAZIV, BODOVI]
MINUS
((P1 TIMES P2) WHERE P1.BODOVI<P2.BODOVI)[P1.NAZIV, P1.BODOVI]
relacioni račun
range of px is predmet
range of py is predmet
px.naziv, px.bodovi
where not exists py (py.bodovi>px.bodovi)
Primer 12: Pronaći studente koji su položili neki predmet od 6 bodova. Izdvojiti indeks, ime, prezime i naziv predmeta.
relaciona algebra
((PREDMET WHERE BODOVI=6)[ID_PREDMETA, NAZIV] JOIN (ISPIT WHERE OCENA>5) JOIN DOSIJE)[INDEKS, IME, PREZIME, NAZIV]
relacioni račun
range of dx is dosije
range of ix is ispit
range of px is predmet
dx.indeks, dx.ime, dx.prezime, px.naziv
where px.bodovi=6 and exists ix(px.id_predmeta=ix.id_predmeta and dx.indeks=ix.indeks and ix.ocena>5)
Primer 13: Pronaći studenta koji je u jednoj godini položio sve predmete. Izdvojiti godinu i indeks.
relaciona algebra
(ISPIT WHERE OCENA>5)[INDEKS, GODINA_ROKA, ID_PREDMETA] DIVIDEBY PREDMET[ID_PREDMETA]
relacioni račun
range of ix, iy is ispit
range of px is predmet
ix.indeks, ix.godina_roka
where forall px(exists iy(px.id_predmeta=iy.id_predmeta and ix.indeks=iy.indeks and ix.ocena>5 and ix.godina_roka=iy.godina_roka)
Zadaci za vežbu: