Un tableau croisé simple
Vous disposez du tableau suivant indiquant les pays médaillés d'or au saut à la perche, par genre, en 2008 et 2012.
| Gender | Year | Country |
|--------|------|---------|
| Men | 2008 | AUS |
| Men | 2012 | FRA |
| Women | 2008 | RUS |
| Women | 2012 | USA |
Effectuez un pivot par Year pour obtenir le tableau remanié et plus clair suivant.
| Gender | 2008 | 2012 |
|--------|------|------|
| Men | AUS | FRA |
| Women | RUS | USA |
Cette activité fait partie du cours
Fonctions de synthèse et de fenêtre dans PostgreSQL
Instructions de l’exercice
- Créez l'extension appropriée.
- Indiquez les noms de colonnes du tableau pivoté.
Exercice interactif pratique
Essayez cet exercice en complétant ce code d’exemple.
-- Create the correct extension to enable CROSSTAB
CREATE EXTENSION IF NOT EXISTS ___;
SELECT * FROM CROSSTAB($$
SELECT
Gender, Year, Country
FROM Summer_Medals
WHERE
Year IN (2008, 2012)
AND Medal = 'Gold'
AND Event = 'Pole Vault'
ORDER By Gender ASC, Year ASC;
-- Fill in the correct column names for the pivoted table
$$) AS ct (___ VARCHAR,
___ VARCHAR,
___ VARCHAR)
ORDER BY Gender ASC;