diff --git a/Zweites Jahr/aufgaben/saveLibaryDataInXml/getRentCountAbove10.sql b/Zweites Jahr/aufgaben/saveLibaryDataInXml/getRentCountAbove10.sql index 97ec8d6..d955c43 100644 --- a/Zweites Jahr/aufgaben/saveLibaryDataInXml/getRentCountAbove10.sql +++ b/Zweites Jahr/aufgaben/saveLibaryDataInXml/getRentCountAbove10.sql @@ -1,4 +1,4 @@ -SELECT ProductID, SUM(Quantity) AS orderAnzahl -FROM OrderDetails -GROUP BY ProductID -ORDER BY orderAnzahl ASC; \ No newline at end of file +SELECT bibNr, COUNT(*) AS orderAnzahl +FROM Ausleihe +GROUP BY bibNr +HAVING COUNT(*) > 10; \ No newline at end of file diff --git a/Zweites Jahr/aufgaben/saveLibaryDataInXml/task.md b/Zweites Jahr/aufgaben/saveLibaryDataInXml/task.md index cd9020f..93ff857 100644 --- a/Zweites Jahr/aufgaben/saveLibaryDataInXml/task.md +++ b/Zweites Jahr/aufgaben/saveLibaryDataInXml/task.md @@ -28,7 +28,7 @@ ### 2.3 SQL ## 2.3.1 - +### Meine Lösung ```sql SELECT book.bibNr, book.titel, COUNT(book.bibNr) AS wieOftAusgeliehen FROM buch AS book @@ -37,10 +37,24 @@ LEFT JOIN Ausleihe AS rent ON book.bibNr = rent.bibNr GROUP BY book.bibNr, book.titel ORDER BY wieOftAusgeliehen ASC ``` +### Lösung des Lehrers +```sql +SELECT a.bibNr, b.titel, COUNT(*) AS wieOftAusgeliehen +FROM Ausleihe, Buch +WHERE AUsleihe.bibNr=Buch.bibNr +WHERE Aulsiehe.ausleihdatum BETWEEN "2015-01-01" AND "2015-12-32" +GROUP BY bibNr, titel +ORDER BY COUNT(*) DESC; +``` ## 2.3.2 -X +```sql +SELECT bibNr, COUNT(*) AS orderAnzahl +FROM Ausleihe +GROUP BY bibNr +HAVING COUNT(*) > 10; -- HAVING bei solchen funktionen +``` ## 2.3.3