Created
August 26, 2014 13:51
-
-
Save baruchel/9f584388dcef84ea4d0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Reproduire la table `CountryLanguage` à la différence près que la colonne Percentage doit maintenant contenir le pourcentage de locuteurs d'une langue dans un pays par rapport au nombre total de locuteurs de cette langue dans le monde. | |
SELECT CountryCode, Language, IsOfficial, | |
(A.Percentage * A.Population / B.nbr) AS Percentage | |
FROM ( | |
SELECT CountryLanguage.*, Country.Population | |
FROM CountryLanguage | |
LEFT JOIN Country | |
ON CountryLanguage.CountryCode = Country.Code | |
) AS A | |
LEFT JOIN ( | |
SELECT Language, SUM(Percentage * Country.Population)/100 AS nbr | |
FROM CountryLanguage | |
LEFT JOIN Country | |
ON CountryLanguage.CountryCode = Country.Code | |
GROUP BY Language | |
) AS B | |
USING(Language); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment