1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
* 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
|