Agrégation · 20 min
Fonctions d'agrégation : COUNT, SUM, AVG, MIN, MAX, ROUND
Apprendre à calculer les statistiques de base : comptage, somme, moyenne, min, max, et arrondi avec ROUND.
Contexte
Pour résumer un jeu de données (compter, totaliser, moyen, min, max), on utilise les fonctions d'agrégation.
Explication
COUNT(*) = nombre de lignes, SUM(col) = total, AVG(col) = moyenne, MIN(col)/MAX(col) = extrêmes.
ROUND(value, nb) arrondit un nombre à nb décimales.
Syntaxe :
SELECT COUNT(*), SUM(col), ROUND(AVG(col),2), MIN(col), MAX(col) FROM une_table;
Exemple guidé
Moyenne des notes du cours 1 (Algèbre) :
SELECT ROUND(AVG(note),2) FROM notes WHERE cours_id=1;
Résultat :
| ROUND(AVG(note),2) |
|---|
| 11.5 |
AVG retour un REAL, on l'arrondit avec ROUND(value,2).
À retenir
COUNT : comptage. SUM : total. AVG : moyenne (retourne REAL). MIN/MAX : extrêmis. ROUND : arrondi à n chiffres.