SELECT practicing queryies on SQLzoo.net - Goorolx/MySQL_playground GitHub Wiki
SQLzoo - SELECT within SELECT tutorial
- Show the name and the population of each country in Europe. Show the population as a percentage of the population of Germany. The format should be Name, Percentage for example:
SELECT name,
CONCAT(ROUND(100*(population / (SELECT population FROM world WHERE name='Germany')),0),'%')
FROM world
WHERE continent = 'Europe'
this one rounds to 0 decimal places but prints like 10 zeros when MsSQL selected, MySQL reults are as expected, nicely rounded no decimals. CONCAT can be replaced by || or + on some SQL versions.
- Which countries have a GDP greater than every country in Europe? [Give the name only.] (Some countries may have NULL gdp values)
SELECT name
FROM world
WHERE gdp > ALL(SELECT gdp
FROM world
WHERE gdp > 0
AND continent = 'Europe')
EZ