Drop links or images here to add them to the editor.

Database schema

GROUP BY groepeert rijen die dezelfde waarde hebben in een kolom. Daarna kun je groepsfuncties (COUNT(), SUM(), AVG(), MAX(), MIN()) toepassen per groep in plaats van op de hele tabel.

In de vraag staat vaak iets als: “hoeveel per bestelling” of “het totaal per klant” — dit is een signaal dat je GROUP BY nodig hebt.

Voorbeeld 1: hoeveel keer is elke bodem besteld?

SELECT bodemcode, COUNT(aantal) AS aantal_besteld
FROM besteldepizza
GROUP BY bodemcode;
bodemcode aantal_besteld
1 2788
2 2905
3 140

Voorbeeld 2: totaal besteld per pizzasoort:

SELECT pizzacode, SUM(aantal) AS totaal_besteld
FROM besteldePizza
GROUP BY pizzacode;
pizzacode totaal_besteld
1 315
2 284
3 224