aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-09-19 17:05:51 +0200
committerlonkaars <loek@pipeframe.xyz>2022-09-19 17:05:51 +0200
commit4956a132478cb219fbaf20b26b0268daa22b98c1 (patch)
tree3bbfdfb7ad24fb0f6adde6f9b831397ea503b7c9
parente67b2b0a58a312f98780e63f6f6121d6b1497438 (diff)
alle huiswerk 3.x klaar
-rw-r--r--huiswerk.md124
1 files changed, 124 insertions, 0 deletions
diff --git a/huiswerk.md b/huiswerk.md
index 1b19fca..c62a7e6 100644
--- a/huiswerk.md
+++ b/huiswerk.md
@@ -67,6 +67,23 @@
|2.24 |`select actcode, datum, count(actcode) as aantal_deelnemers from belangstelling group by datum, actcode having datum is not null and aantal_deelnemers >= 2 order by actcode, datum;`|
|2.25 |`select planningsnr, sum(betaald) as betaald from inschrijving group by planningsnr;`|
|2.26 |`select planningsnr from inschrijving group by planningsnr having sum(betaald) = 0;`|
+|3.01 |`select count(*) as aantal_records_studenten from student;`|
+|3.02 |`select count(*) as aantal_records_studenten from opleiding;`|
+|3.03 |[`select count(*) from student cross join opleiding;`](#303)|
+|3.04 |[open vraag](#304)|
+|3.05 |`select * from student inner join opleiding on student.oplcode = opleiding.oplcode;`|
+|3.06 |`select count(*) as aantal_studenten_ABCT from student inner join opleiding on student.oplcode = opleiding.oplcode where academie = "ABCT";`|
+|3.07 |`select distinct naam from student inner join belangstelling on student.studentnr = belangstelling.studentnr;`|
+|3.08 |`select distinct actomschr from activiteit inner join belangstelling on activiteit.actcode = belangstelling.actcode;`|
+|3.09 |`select distinct naam from student inner join inschrijving on inschrijving.studentnr = student.studentnr where inschrijving.betaald = 1 and inschrijving.planningsnr = 12;`|
+|3.10 |`select planningsnr, actomschr, datum from planning inner join activiteit on activiteit.actcode = planning.actcode order by planningsnr;`|
+|3.11 |`select planning.actcode, planning.datum, student.naam from inschrijving inner join planning on planning.planningsnr = inschrijving.planningsnr inner join student on student.studentnr = inschrijving.studentnr order by planning.actcode, planning.datum, student.naam;`|
+|3.12 |`select opleiding.academie, count(inschrijving.betaald) as aantal_niet_betaald from student inner join opleiding on opleiding.oplcode = student.oplcode inner join inschrijving on inschrijving.studentnr = student.studentnr where inschrijving.betaald = 0 group by academie;`|
+|3.13 |`select student.naam, sum(activiteit.prijs) as betaald from inschrijving inner join student on student.studentnr = inschrijving.studentnr inner join planning on planning.planningsnr = inschrijving.planningsnr inner join activiteit on activiteit.actcode = planning.actcode where inschrijving.betaald = 1 group by student.naam order by student.studentnr;`|
+|3.14 |`select opleiding.academie, sum(activiteit.prijs) as nog_te_betalen from inschrijving inner join student on student.studentnr = inschrijving.studentnr inner join opleiding on opleiding.oplcode = student.oplcode inner join planning on planning.planningsnr = inschrijving.planningsnr inner join activiteit on activiteit.actcode = planning.actcode where inschrijving.betaald = 0 group by academie;`|
+|3.15 |`select activiteit.actomschr, sum(activiteit.prijs) as openstaand_bedrag from inschrijving inner join planning on planning.planningsnr = inschrijving.planningsnr inner join activiteit on activiteit.actcode = planning.actcode where inschrijving.betaald = 0 group by actomschr order by openstaand_bedrag desc;`|
+|3.16 |[open vraag](#316)|
+|3.17 |[open vraag](#317)|
## 1.07
@@ -174,3 +191,110 @@ De `count()` functie telt het aantal rijen met een "truthy" waarde. Omdat bij
`count(*)` elke rij minstens een kolom heeft met een gedefinieerde waarde krijg
je 8, terwijl in de 'academie' kolom een keer NULL voorkomt.
+# 3.03
+
+```
+MariaDB [mysql]> select count(*) from student cross join opleiding;
++----------+
+| count(*) |
++----------+
+| 144 |
++----------+
+1 row in set (0.000 sec)
+
+MariaDB [mysql]>
+```
+
+Het rijenaantal is de hoeveelheid rijen van de eerste tabel vermenigvuldigd met
+de hoeveelheid rijen in de tweede tabel (in dit geval 8 * 18 = 144).
+
+# 3.04
+
+`cross join` maakt elke combinatie van rijen.
+
+# 3.16
+
+```
+MariaDB [mysql]> select omschrijving, count(studentnr) as aantal_studenten from student as s join opleiding as o on s.oplcode = o.oplcode group by omschrijving having count(studentnr) > 2;
++------------------------+------------------+
+| omschrijving | aantal_studenten |
++------------------------+------------------+
+| Informatica | 5 |
+| Technische Informatica | 4 |
++------------------------+------------------+
+2 rows in set (0.000 sec)
+
+MariaDB [mysql]>
+```
+
+Deze query laat voor elke opleiding met meer dan 2 studenten de naam en het
+studentenaantal zien.
+
+# 3.17
+
+1. Tabel maken met omschrijving en unieke studentnummers
+ ```
+ MariaDB [mysql]> select omschrijving, studentnr from student join opleiding on student.oplcode = opleiding.oplcode;
+ +--------------------------+-----------+
+ | omschrijving | studentnr |
+ +--------------------------+-----------+
+ | Bouwkunde | 16 |
+ | Civiele Techniek | 17 |
+ | Civiele Techniek | 18 |
+ | Electrotechniek | 5 |
+ | Electrotechniek | 9 |
+ | Informatica | 1 |
+ | Informatica | 2 |
+ | Informatica | 6 |
+ | Informatica | 7 |
+ | Informatica | 10 |
+ | Technische Bedrijfskunde | 14 |
+ | Technische Bedrijfskunde | 15 |
+ | Technische Informatica | 3 |
+ | Technische Informatica | 4 |
+ | Technische Informatica | 8 |
+ | Technische Informatica | 11 |
+ | Werktuigbouw | 12 |
+ | Werktuigbouw | 13 |
+ +--------------------------+-----------+
+ 18 rows in set (0.000 sec)
+ ```
+2. Studentnummers tellen en groeperen per opleiding
+ ```
+ MariaDB [mysql]> select omschrijving, count(studentnr) from student join opleiding on student.oplcode = opleiding.oplcode group by omschrijving;
+ +--------------------------+------------------+
+ | omschrijving | count(studentnr) |
+ +--------------------------+------------------+
+ | Bouwkunde | 1 |
+ | Civiele Techniek | 2 |
+ | Electrotechniek | 2 |
+ | Informatica | 5 |
+ | Technische Bedrijfskunde | 2 |
+ | Technische Informatica | 4 |
+ | Werktuigbouw | 2 |
+ +--------------------------+------------------+
+ 7 rows in set (0.000 sec)
+ ```
+3. Verberg alle opleidingen met 2 of minder studenten
+ ```
+ MariaDB [mysql]> select omschrijving, count(studentnr) from student join opleiding on student.oplcode = opleiding.oplcode group by omschrijving having count(studentnr) > 2;
+ +------------------------+------------------+
+ | omschrijving | count(studentnr) |
+ +------------------------+------------------+
+ | Informatica | 5 |
+ | Technische Informatica | 4 |
+ +------------------------+------------------+
+ 2 rows in set (0.000 sec)
+ ```
+4. Kolomnamen en tabelaliasen toevoegen
+ ```
+ MariaDB [mysql]> select omschrijving, count(studentnr) as aantal_studenten from student as s join opleiding as o on s.oplcode = o.oplcode group by omschrijving having count(studentnr) > 2;
+ +------------------------+------------------+
+ | omschrijving | aantal_studenten |
+ +------------------------+------------------+
+ | Informatica | 5 |
+ | Technische Informatica | 4 |
+ +------------------------+------------------+
+ 2 rows in set (0.000 sec)
+ ```
+