* DBII Praktikum 3 */ /* ================ */ /* Aufgabe 1: */ /* ---------- */ select ISBN, BTITEL from BUCH where LEIHNR in (select LEIHNR from AUTOR_BUCH where ACODE in (select ACODE from AUTOR where ANAME = 'Charles Dickens')); /* oder */ select ISBN,BTITEL from BUCH where LEIHNR in (select ab.LEIHNR from Autor a, AUTOR_BUCH ab where a.ACODE = ab.ACODE and a.ANAME = 'Charles Dickens'); /* oder */ select b.ISBN,b.BTITEL from Autor a, AUTOR_BUCH ab, BUCH b where a.ACODE = ab.ACODE and ab.LEIHNR = b.LEIHNR and a.ANAME = 'Charles Dickens'; /* Aufgabe 2: */ /* ---------- */ select b.LEIHNR, b.ISBN, b.BTITEL, b.ERSCHJAHR from Autor a, AUTOR_BUCH ab, BUCH b where a.ACODE = ab.ACODE and ab.LEIHNR = b.LEIHNR and a.ANAME = 'Barbara Wood'; select * from BUCH where LEIHNR in (select LEIHNR from AUTOR_BUCH where ACODE in (select ACODE from AUTOR where ANAME = 'Barbara Wood')); /* Aufgabe 3: */ /* ---------- */ select e.ENAME, a.DATUM, a.BACKDATE, a.OVER, o.LEIHTYP from LEIHOBJEKT o, AUSLEIHE a, ENTLEIHER e where o.LEIHNR = a.LEIHNR and a.ENR = e.ENR order by a.datum; /* Aufgabe 4: */ /* ---------- */ SELECT e.ENAME, count(*) FROM AUSLEIHE a, ENTLEIHER e WHERE a.ENR = e.ENR and a.datum > '31.12.2005' GROUP BY e.ENAME having count(*) > 1 order by count(*) desc; /* Aufgabe 5: */ /* ---------- */ select b.BTITEL, b.ERSCHJAHR from Autor a, AUTOR_BUCH ab, BUCH b where a.ACODE = ab.ACODE and ab.LEIHNR = b.LEIHNR and a.ANAME = 'Annette Weiler' and b.ERSCHJAHR in (select max(b.ERSCHJAHR) from Autor a, AUTOR_BUCH ab, BUCH b where a.ACODE = ab.ACODE and ab.LEIHNR = b.LEIHNR and a.ANAME = 'Annette Weiler'); /* Aufgabe 6: */ /* ---------- */ select e.ENAME, a.DATUM, a.BACKDATE, a.OVER, o.LEIHTYP from LEIHOBJEKT o, AUSLEIHE a, ENTLEIHER e where o.LEIHNR = a.LEIHNR and a.ENR = e.ENR and ( o.LEIHTYP = 'a' or o.LEIHTYP ='z' ) and (a.datum between '28.01.2006' and '05.02.2006'); /* Aufgabe 7: */ /* ---------- */ SELECT lo.leihnr LEIHNR, lo.leihtyp LEIHTYP, e.TITEL from LEIHOBJEKT lo, (SELECT z.leihnr NR,z.ztitel TITEL from ZEITSCHRIFT z UNION SELECT a.leihnr NR ,atitel TITEL from AUDIO a UNION SELECT b.leihnr NR, b.btitel TITEL FROM BUCH b) e WHERE lo.leihnr=e.NR ORDER BY LEIHTYP, e.TITEL; /* Aufgabe 8: */ /* ---------- */ select e.ENAME, sum(a.OVER) * 2 from AUSLEIHE a, ENTLEIHER e where a.ENR = e.ENR GROUP BY e.Ename having sum(a.OVER) > 0; /* Aufgabe 9: */ /* ---------- */ select distinct a.acode,a.aname from AUTOR a, autor_buch ab WHERE a.acode=ab.acode and EXISTS (SELECT * FROM ausleihe al where ab.leihnr = al.leihnr); select a.acode,a.aname from AUTOR a WHERE EXISTS (SELECT * FROM autor_buch ab, ausleihe al where a.acode = ab.acode and ab.leihnr = al.leihnr); /* Aufgabe 10: */ /* ---------- */ select b.leihnr, b.isbn from buch b WHERE not EXISTS ( SELECT * from ausleihe a where a.leihnr = b.leihnr); /* geht nicht */ select * from buch WHERE not EXISTS ( SELECT * FROM BUCH Natural JOIN AUSLEIHE); /* Aufgabe 11: */ /* ---------- */ select e.enr, e.ename from entleiher e where exists (select * from ausleihe a where a.enr=e.enr and a.over >0); _______________________________________________________________ SMS schreiben mit WEB.DE FreeMail - einfach, schnell und kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192