> For the complete documentation index, see [llms.txt](https://metis-montessori-lyceum.gitbook.io/sql-0/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://metis-montessori-lyceum.gitbook.io/sql-0/4-grouperen/groupering.md).

# Uitleg

In het vorige hoofdstuk heb je gezien dat je het totaal aantal rijen van een tabel kunt laten tellen en afdrukken.

En je kunt de som van alle getallen in een kolom optellen, enz.

Je kunt de tabel ook indelen in groepjes van dezelfde soort, en de aantallen in die groepjes laten tellen en afdrukken (of optellen, of het gemiddelde bepalen, enz).

Stel dat je een lijstje wilt van alle landen, met per land het aantal klanten dat daar woont.&#x20;

Dat kan met de volgende SQL query:

```sql
select country, count(*) 
from Customer 
group by country;
```

Nog een voorbeeldje, heb je een idee wat je hier doet? \[probeer het uit]

```sql
select GenreID, sum(Milliseconds) 
from Track 
group by GenreID;
```

### Having

Stel dat je een lijstje wilt van de Tracks en de totale lengte per GenreID, maar dan alleen de tracks die een totale lengte van meer dan 20000 MS hebben.

Bij een voorwaarde die betrekking heeft op een functie, waarbij group by gebruikt wordt, dan moet je gebruik maken van Having.

De query moet dan als volgt worden geformuleerd:

```sql
select GenreId, sum(Milliseconds)
from Track
Group by GenreID
Having sum(Milliseconds) > 20000;
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://metis-montessori-lyceum.gitbook.io/sql-0/4-grouperen/groupering.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
