Die Bibliothek will ihrem eifrigsten Leser einen kleinen Preis geben. Verbinde loans und books und rechne aus, wie viele Seiten jeder reader insgesamt ausgeliehen hat (pages zusammengezählt). Wähl reader und die Summe aus.
idPKtitleauthorgenrepagesyearidPKbook_idFKreaderdaysloans.book_id → books.id
| id | title | author | genre | pages | year |
|---|---|---|---|---|---|
| 1 | The Night Garden | Mia Lane | story | 210 | 2015 |
| 2 | Stars for Kids | Tom Hart | science | 96 | 2020 |
| 3 | Lost at Sea | Mia Lane | story | 340 | 2011 |
| 4 | Easy Bread | Rosa Bell | food | 128 | 2019 |
| 5 | The Bug Book | Tom Hart | science | 64 | 2022 |
| 6 | Soup Days | Rosa Bell | food | 150 | 2008 |
| 7 | The Red Kite | Ann Cole | story | 180 | 2021 |
| 8 | Rocks and Rivers | Ann Cole | science | 220 | 2017 |
| id | book_id | reader | days |
|---|---|---|---|
| 1 | 1 | Leo | 14 |
| 2 | 2 | Nora | 7 |
| 3 | 1 | Sam | NULL |
| 4 | 4 | Leo | 21 |
| 5 | 5 | Nora | NULL |
| 6 | 3 | Ivy | 10 |
| 7 | 2 | Sam | 5 |
| 8 | 7 | Ivy | 12 |
idPKtitleauthorgenrepagesyearidPKbook_idFKreaderdaysloans.book_id → books.id
| id | title | author | genre | pages | year |
|---|---|---|---|---|---|
| 1 | The Night Garden | Mia Lane | story | 210 | 2015 |
| 2 | Stars for Kids | Tom Hart | science | 96 | 2020 |
| 3 | Lost at Sea | Mia Lane | story | 340 | 2011 |
| 4 | Easy Bread | Rosa Bell | food | 128 | 2019 |
| 5 | The Bug Book | Tom Hart | science | 64 | 2022 |
| 6 | Soup Days | Rosa Bell | food | 150 | 2008 |
| 7 | The Red Kite | Ann Cole | story | 180 | 2021 |
| 8 | Rocks and Rivers | Ann Cole | science | 220 | 2017 |
| id | book_id | reader | days |
|---|---|---|---|
| 1 | 1 | Leo | 14 |
| 2 | 2 | Nora | 7 |
| 3 | 1 | Sam | NULL |
| 4 | 4 | Leo | 21 |
| 5 | 5 | Nora | NULL |
| 6 | 3 | Ivy | 10 |
| 7 | 2 | Sam | 5 |
| 8 | 7 | Ivy | 12 |
SELECT loans.reader, books.pages FROM loans JOIN books ON loans.book_id = books.id -- dein Code hier: tausch books.pages gegen SUM(books.pages), und GROUP BY loans.reader ;
Ausführen zeigt, was deine Abfrage liefert. Wenn es passt, drück auf Abgeben.