diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-09-16 15:49:34 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-09-16 15:49:34 +0200 |
commit | e67b2b0a58a312f98780e63f6f6121d6b1497438 (patch) | |
tree | 24391aa30222453ec93c9d8bd3bb40495e5254cf | |
parent | d11270807080629f816ed59ece80c4eea17d9176 (diff) |
alle huiswerk 2.x klaar
-rw-r--r-- | huiswerk.md | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/huiswerk.md b/huiswerk.md index fc0681f..1b19fca 100644 --- a/huiswerk.md +++ b/huiswerk.md @@ -41,6 +41,32 @@ |1.37 |`select count(distinct oplcode) as aantal_opleiding_met_student from student;`| |1.38 |`select count(actcode) as aantal_studenten_KRS from belangstelling where actcode = "KRS";`| |1.39 |`select count(*) from inschrijving where planningsnr >= 4 and planningsnr <= 9 and betaald = 0;`| +|2.01 |`select naam from student where instr(naam, "a");`| +|2.02 |`select ucase(naam) from student;`| +|2.03 |`select naam, concat(left(naam, 2), right(naam, 2)) as wachtwoord from student;`| +|2.04 |`select left(naam, instr(naam, " ") - 1) as voornaam, right(naam, length(naam) - instr(naam, " ")) as achternaam from student;`| +|2.05 |`select round(avg(prijs),1) as gemiddelde_prijs from activiteit;`| +|2.06 |`select naam, replace(oplcode, "IN", "Informatica") as opleiding from student;`| +|2.07 |`select left(naam, instr(naam, " ") - 1) as voornaam from student where right(naam, length(naam) - instr(naam, " ")) = "Tomeloos";`| +|2.08 |`select count(*) as aantal_eindigend_op_S from activiteit where right(actcode, 1) = "S";`| +|2.09 |`select sum(prijs) as totaalprijs from activiteit where left(actcode, 1) = "K" and right(actcode, 1) = "S";`| +|2.10 |`select * from opleiding where length(oplcode) > 2 order by oplcode;`| +|2.11 |`select actomschr, prijs, prijs + 1 as nieuwe_prijs from activiteit;`| +|2.12 |`select actomschr, prijs, round(prijs * 1.05, 2) as nieuwe_prijs from activiteit;`| +|2.13 |`select actomschr, prijs, round(prijs * 1.21, 2) as bruto_prijs from activiteit order by bruto_prijs desc;`| +|2.14 |`select actomschr, prijs, round(prijs / 1.21, 2) as netto_prijs from activiteit where prijs < 20.0 order by netto_prijs desc;`| +|2.15 |`select * from activiteit where prijs between 10 and 25;`| +|2.16 |`select * from activiteit where prijs > 10 and prijs < 25;`| +|2.17 |`select * from student where oplcode in("ET", "TI") order by oplcode asc, naam asc;`| +|2.18 |`select * from student where naam like "%a%";`| +|2.19 |`select * from student where naam like "_oo%" and right(naam, length(naam) - instr(naam, " ")) not like "Tomeloos";`| +|2.20 |[open vraag](#220)| +|2.21 |`select academie, count(academie) from opleiding where academie is not NULL group by academie order by academie desc;`| +|2.22 |`select actcode, count(actcode) as aantal_deelnemers from belangstelling group by actcode;`| +|2.23 |`select actcode, datum, count(actcode) as aantal_deelnemers from belangstelling group by datum, actcode order by actcode, datum;`| +|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;`| ## 1.07 @@ -122,3 +148,29 @@ Dit commando geeft een foutmelding, maar werkt normaal wanneer het `order by actcode` gedeelte na het `from planning` gedeelte komt. Dus zijn de volgorde van SQL statements belangrijk. +## 2.20 + +``` +MariaDB [mysql]> select count(*) from opleiding; ++----------+ +| count(*) | ++----------+ +| 8 | ++----------+ +1 row in set (0.000 sec) + +MariaDB [mysql]> select count(academie) from opleiding; ++-----------------+ +| count(academie) | ++-----------------+ +| 7 | ++-----------------+ +1 row in set (0.000 sec) + +MariaDB [mysql]> +``` + +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. + |