SUM and COUNT -- SQLZOO
阿新 • • 發佈:2020-07-29
SUM and COUNT
注意:where語句中對錶示條件的需要用單引號,下面的譯文使用的是有道翻譯如有不正確,請直接投訴有道
01.Show the totalpopulationof the world.
譯文:展示世界總人口。
SELECT SUM(population) FROM world
02.List all the continents - just once each.
譯文:列出所有的大陸——每個大陸只列出一次。
SELECT DISTINCT continent FROM world
03.Give the total GDP of Africa
譯文:看看非洲的GDP總量
SELECTSUM(gdp)FROM worldWHERE continent ='Africa'
04.How many countries have anareaof at least 1000000
譯文:有多少國家的面積至少有100萬。
SELECT COUNT(name) FROM world WHERE area >= 1000000
05.What is the totalpopulationof ('Estonia', 'Latvia', 'Lithuania')
譯文:愛沙尼亞、拉脫維亞、立陶宛的總人口是多少?
SELECT SUM(population) FROM world WHERE name IN ('Estonia', 'Latvia', 'Lithuania')
06.For eachcontinentshow thecontinentand number of countries.
譯文:表示每個洲的洲數和國家數。
SELECT continent, COUNT(name) FROM world GROUP BY continent
07.For eachcontinentshow thecontinentand number of countries with populations of at least 10 million.
譯文:每一洲顯示人口至少為1 000萬的洲和國家數目。
SELECT continent, COUNT(name) FROM world WHERE population > 10000000 GROUP BY continent
08.List the continents thathavea total population of at least 100 million.
譯文:列出總人口至少為1億的大洲。
SELECT continent FROM world GROUP BY continent HAVING SUM(population) >= 100000000
練習網址:https://sqlzoo.net/wiki/SUM_and_COUNT
------------------------------------------------------------------------------------------------------------------------------------------------------------------