Comparer des groupes

Création de rapports en SQL

Tyler Pernes

Learning & Development Consultant

Types de mesures

  • Mesures de volume
  • Mesures d'efficacité
Création de rapports en SQL

Mesures de volume

  • Évoluent avec la taille
Création de rapports en SQL

Mesures de volume

  • Évoluent avec la taille

Création de rapports en SQL

Mesures de volume

  • Évoluent avec la taille

Création de rapports en SQL

Calcul du pourcentage du total

basketball_points table
+----------+------------+---------+
| team_id  | player_id  | points  |
|----------|------------|---------|
| 1        | 482        | 92      |
| 1        | 165        | 47      |
| 2        | 222        | 64      |
+----------+------------+---------+
SELECT team_id, SUM(points) AS points
FROM basketball_points
GROUP BY team_id;
Création de rapports en SQL

Calcul du pourcentage du total

basketball_points table
+----------+------------+---------+
| team_id  | player_id  | points  |
|----------|------------|---------|
| 1        | 482        | 92      |
| 1        | 165        | 47      |
| 2        | 222        | 64      |
+----------+------------+---------+
+----------+---------+
| team_id  | points  |
|----------|---------|
| 1        | 782     |
| 2        | 625     |
| 3        | 487     |
| 4        | 398     |
+----------+---------+
Création de rapports en SQL

Calcul du pourcentage du total

Étape 1 : calculer le total

SELECT 
    team_id, 
    SUM(points) AS points
    SUM(points) OVER () AS total_points
FROM basketball_points
GROUP BY team_id;

Étape 2 : calculer le pourcentage du total

SELECT 
    team_id, 
    SUM(points) AS points
    SUM(points) / SUM(points) OVER () AS perc_of_total
FROM basketball_points
GROUP BY team_id;
Création de rapports en SQL

Calcul du pourcentage du total

Résultats :

+----------+---------+---------------+
| team_id  | points  | perc_of_total |
|----------|---------|---------------|
| 1        | 782     | .34           |
| 2        | 625     | .27           |
| 3        | 487     | .21           |
| 4        | 398     | .17           |
+----------+---------+---------------+
Création de rapports en SQL

Calcul du pourcentage du total

Pourcentage des points marqués par joueur pour chaque équipe :

SELECT 
    player_id,
    team_id,
    SUM(points) AS points
    SUM(points) / (SUM(points) OVER (PARTITION BY team_id)) AS perc_of_team
FROM basketball_points
GROUP BY player_id, team_id;
Création de rapports en SQL

Calcul du pourcentage du total

Résultats :

+-----------+---------+---------+--------------+
| player_id | team_id | points  | perc_of_team |
|-----------|---------|---------|--------------|
| 482       | 1       | 92      | .12          |
| 165       | 1       | 47      | .06          |
| 222       | 2       | 64      | .10          |
+-----------+---------+---------+--------------+
Création de rapports en SQL

Mesures d'efficacité

  • Ne varie pas avec la taille
  • Généralement un ratio
Création de rapports en SQL

Mesures d'efficacité

  • Ne varie pas avec la taille
  • Généralement un ratio

Création de rapports en SQL

Mesures d'efficacité

  • Ne varie pas avec la taille
  • Généralement un ratio

Création de rapports en SQL

Indice de performance

  • Compare la performance à une référence
  • Référence souvent une moyenne ou une médiane
Création de rapports en SQL

Indice de performance

basketball_summary table
+----------+--------+---------+
| team_id  | games  | points  |
|----------|--------|---------|
| 1        | 24     | 782     |
| 2        | 20     | 625     |
| 3        | 12     | 487     |
+----------+--------+---------+
  • Points par match comme mesure de performance ?
Création de rapports en SQL

Indice de performance

Étape 1 : points par match pour chaque équipe

SELECT 
    team_id, 
    points/games AS team_ppg
FROM basketball_summary;

Étape 2 : points par match pour l'ensemble de la ligue

SELECT 
    team_id, 
    points/games AS team_ppg,
    SUM(points) OVER () / SUM(games) OVER () AS league_ppg
FROM basketball_summary;
Création de rapports en SQL

Indice de performance

Étape 3 : indice de performance

SELECT 
    team_id, 
    points/games AS team_ppg,
    SUM(points) OVER () / SUM(games) OVER () AS league_ppg,
    (points/games) 
    / 
    (SUM(points) OVER () / SUM(games) OVER ()) AS perf_index
FROM basketball_summary;
Création de rapports en SQL

Indice de performance

Étape 3 : indice de performance

+----------+----------+------------+-------------+
| team_id  | team_ppg | league_ppg | perf_index  |    
|----------|----------|------------|-------------|
| 1        | 32.6     | 33.8       | 0.96        |
| 2        | 31.3     | 33.8       | 0.92        |
| 3        | 40.6     | 33.8       | 1.20        |
+----------+----------+------------+-------------+
1 Les résultats indiquent clairement que l'équipe trois marque 20 % plus de points que la moyenne de la ligue.
Création de rapports en SQL

À vos requêtes !

Création de rapports en SQL

Preparing Video For Download...