# Aufgabe 1) ### Relationenalgebra: 1. $\pi _{\text{LastName}}(\sigma_{\text{Position=Defence} \wedge \text{Name='FC Barcelona'}}(\rho_{\text{TeamNo} \leftarrow \text{playsFor}}(\text{Player}) \bowtie \text{Team}))$ 2. $\pi_{\text{StadiumName}}(\sigma_{\neg(\text{Situation='Own Goal'})}(\rho_{\text{InGame} \leftarrow \text{Nr}}(\text{Match}) \bowtie \text{Goal}))$ ### Tupelkalkül 1. $\{[t\text{.LastName}] \mid\ \text{Player}(t) \wedge \text{Team}(t^{\prime}) \wedge t\text{.playsFor} = t^{\prime}\text{.TeamNo}\wedge t^{\prime}\text{.Name} = \text{'FC Barcelona'} \wedge t\text{.Position} = \text{Defence}\}$ mit: $t: \{\text{PlayerNo}, \text{playsFor}, \text{FirstName}, \text{LastName}, \text{Position}\}$ $t^{\prime}: \{\text{TeamNo}, \text{Name}\}$ 2. $\{[t\text{.StadiumName}] \mid\ \text{Match}(t) \wedge \text{Goal}(t^{\prime}) \wedge t\text{.Nr} = t^{\prime}\text{.InGame} \wedge \neg(t^{\prime}.\text{Situation} = \text{'Own Goal'})\}$ mit: $t: \{\text{Nr}, \text{Home}, \text{Opponent}, \text{Date}, \text{StadiumLocation}, \text{StadiumName}\}$ $t^{\prime}: \{\text{GoalsOfPlayerNo}, \text{GoalsOfTeam}, \text{InGame}, \text{Minute}, \text{Situation}\}$ Beide Aussagen sind sicher. Bei 1. sollte dies klar sein. 2. ist sicher, da das t durch Goal(t') schon eingeschränkt wurde und es somit nicht beliebig viele Möglichkeiten gibt ### Domänenkalkül 1. $\{[n] \mid \exists n \exists z \exists t\exists x. \ \ \text{Player}(z,t,x,n,\text{'Defence'}) \wedge \text{Team}(t,\text{'FC Barcelona'})\}$ 2. $\{[n] \mid \exists z \exists h \exists o \exists d \exists l \exists n \exists a \exists t \exists m . \ \ \text{Match}(z,h,o,d,l,n) \wedge \neg \text{Goal}(a,t,z,m,\text{'Own Goal'})\}$ Die erste Anfrage ist sicher, da ein Wert bereits festgelegt wurde und somit kein Ausdruck mehr komplett "frei" ist. Die zweite Aussage ist unsicher, da beliebige a,t,m für den ~Goal-Ausdruck True zurück geben ### SQL 1. p.SELECT LastName FROM Player as p, Team as t WHERE t.TeamNo=p.playsFor AND p.Position='Defence' AND t.Name='FC Barcelona' 2. SELECT m.StadiumName FROM Match as m, Goal as g WHERE m.Nr=g.InGame AND g.Situation<>'Own Goal' # Aufgabe 2) ## 1. ### Relationale Algebra: a) $\pi_{\text{Title}}(\sigma_{\text{SCH<4}}(\text{Course}))$ <!--- pi Title (sigma SCH < 4 (Course)) ---> b) $\pi_{Rank,Topic}(\rho_{Boss \leftarrow PerNo}(Professor) \bowtie Assistant)$ <!--- pi Rank,Topic (Professor ⨝ Professor.PerNo=Assistent.Boss Assistent) ---> c) pi Name (sigma Title='Grundzuege' ∧ Title2='Ethik' ((sigma StuNo=StuNo2 (attend ⨯ rho StuNo2 ← StuNo, CouNo2 ← CouNo (attend))) ⨝ Course ⨝ rho CouNo2 ← CouNo, Title2 ← Title, SCH2 ← SCH, TaughtBy2 ← TaughtBy (Course) ⨝ Student)) d) $\pi_{Name}(Professor) - \pi_{Name}(Professor \bowtie \rho_{PerNo \leftarrow TaughtBy}(Course))$ <!--- pi Name (Professor) - pi Name (Professor ⨝ rho PerNo ← TaughtBy (Course)) ---> e) $\pi_{Predecessor} (\sigma_{Title='Wissenschaftstheorie'} (\rho_{Successor \leftarrow CouNo} (Course) \bowtie require))$ <!--- pi Predecessor (sigma Title='Wissenschaftstheorie' (rho Successor ← CouNo (Course) ⨝ require)) ---> ##### Ergebnisse a) | Title | | -------------------- | | Erkenntnistheorie | | Maeeutik | | Wissenschaftstheorie | | Bioethik | | Der Wiener Kreis | | Glaube und wissen | b) | Rank | Topic | |------------------|----------------------| | C4 | Ideenlehre | | C4 | Syllogistik | | C4 | Sprachtheorie | | C3 | Planetenbewegung | | C3 | Keplersche Gesetze | | C3 | Gott und Natur | c) | Name | | -------- | | Theophrastos | d) | Name | | -------- | | Kopernikus | | Curie | e) | Predecessor | | -------- | | 5043 | | 5041 | ### SQL a) SELECT Title FROM Course WHERE SCH < 4; b) SELECT Rank FROM Professor as p, Assistant as a WHERE a.Boss = p.PerNo; #### // Ist das hier ein 'das eine und/oder das andere' oder ist das ein 'das eine und das andere'? #### https://www.w3schools.com/Sql/sql_in.asp Das hier sagt, dass es ein 'or' ist. Damit würde der Ausdruck nicht stimmen c) SELECT Name FROM Student as s,attend as a, Course as c WHERE s.StuNo = a.StuNo AND a.CouNo = c.CouNo AND c.Title IN('Ethik', 'Grundzüge'); c2) SELECT s.Name FROM Student as s, attend as a1, attend as a2, Course as c1, Course as c2 WHERE a1.StuNo=a2.StuNo AND s.StuNo=a1.StuNo AND a1.CouNo=c1.CouNo AND a2.CouNo=c2.CouNo AND c1.Title='Grundzuege' AND c2.Title='Ethik' #### // Ist meiner Meinung nach falsch. Würde alle mit allen verbinden, bei denen p.PerNo != c.TaughtBy und dann danach die Namen selecten. Macht denke ich nicht das, was es soll. Meinen Lösungsvorschlag hab ich drunter geschrieben d) SELECT Name FROM Professor as p, Course as c WHERE p.PerNo != c.TaughtBy; d2) SELECT p.Name FROM Professor as p LEFT JOIN Course as c ON p.PerNo=c.TaughtBy WHERE c.TaughtBy is NULL #### // Der Ausdruck ist kaputt. Hab meinen Vorschlag drunter geschrieben e) SELECT r.CouNo FROM require as r, Course as c WHERE r.Successor = SELECT c.CouNo FROM Course as c WHERE c.Title ='Wissenschaftstheorie'; e2) SELECT r.Predecessor FROM Course as c, require as r WHERE c.CouNo=r.Successor AND c.Title='Wissenschaftstheorie' ## 2. ### umgangssprachlich TODO: a) Die Professoren, welche keinen Assistenten besitzen b) Die Studenten, welche Vorlesungen mit mehr als 2 SCH besuchen ### Relationale Algebra a) $Professor - (Professor \bowtie \rho_{PerNo \leftarrow Boss}(\pi_{Boss}(\rho_{Boss \leftarrow PerNo}(Professor) \bowtie \rho_{NameA \leftarrow Name}(Assistent))))$ ;) <!--- Professor - (Professor ⨝ (rho PerNo ← Boss (pi Boss (rho Boss ← PerNo (Professor) ⨝ rho NameA ← Name Assistent)))) ---> b) $Student \bowtie (\pi_{StuNo}(\sigma_{SCH>2}(Student \bowtie (Course \bowtie attend))))$ <!--- Student ⨝ (pi StuNo (sigma SCH>2 (Student ⨝ (Course ⨝ attend)))) ---> ### SQL 1. SELECT p.* FROM Professor as p LEFT JOIN Assistent as a ON p.PerNo=a.Boss WHERE a.PerNo is NULL 2. SELECT s.* FROM Student as s, attend as a, Course as c WHERE a.StuNo=s.StuNo AND c.CouNo=a.CouNo AND c.SCH > 2 # Fragen - Aufgabe 2) 1.b Was da Topic? Topic ist kein Fachgebiet? Welches Fachgebiet sollen die da haben? Ist damit einfach nur gemeint, dass man Profs mit Assistenten abfragen soll? Wieso ist denn dann Topic gefragt? # Aufgabe 3) 1. CREATE VIEW ExView(StuNo,Title,PerNo) AS (SELECT e.StuNo, c.Title, e.PerNo FROM examine e, Course c WHERE e.CouNo=c.CouNo) 2. CREATE VIEW CouView(VorlNr, Titel, SWS, gelesenVon, ProfTotal) AS ( SELECT VorlNr, Titel, SWS, gelesenVon, ProfTotal from Vorlesungen as c, ( SELECT PersNr, COUNT(VorlNr) as ProfTotal FROM Professoren, Vorlesungen WHERE PersNr = gelesenVon GROUP BY PersNr ) as k WHERE k.PersNr = c.gelesenVon ) https://onecompiler.com/mysql/3xzvcu2x5 #### Hier noch die Namen ändern, falls das so passt 3. Die erste Sicht ist änderbar, da die Werte dort direkt die Werte auf den dahinter liegenden Datenbanken abbilden. Die zweite Sicht ist nicht änderbar, da die Anzahl der Course gezählt wird. Würde man diese abändern wollen, so müssten neue Datenbankeinträge erstellt/gelöscht werden und nicht einfach nur eine Zahl geändert