http://zh.sqlzoo.net/wiki/SUM_and_COUNT/zh
name:國家名稱
continent:洲份
area:面積
population:人口
gdp:國內(nèi)生產(chǎn)總值
world(name,continent, area, population, gdp)
1.
展示世界的總?cè)丝凇?/p>
Select sum(population)from world
2.
列出所有的洲份, 每個(gè)只有一次。
Select distinct(continent)from world
3.
找出非洲(Africa)的GDP總和。
Select sum(GDP)
From world
Where CONTINENT=’Africa’
4.
有多少個(gè)國家具有至少百萬(1000000)的面積。
SELECT count(NAME)FROM world
WHEREAREA>=1000000
5.
('France','Germany','Spain')(“法國”,“德國”,“西班牙”)的總?cè)丝谑嵌嗌伲?/p>
Selectsum(population) from world
Where namein('France','Germany','Spain')
6.
對(duì)於每一個(gè)洲份,顯示洲份和國家的數(shù)量。
Select continent,count(name)from world
Group by continent
說明:按照洲份“continent”分類得出洲份的名稱,然后根據(jù)洲份的名稱對(duì)國家進(jìn)行計(jì)數(shù)。
Group by 為分組函數(shù)。Count為計(jì)數(shù)函數(shù)。
7.
對(duì)於每一個(gè)洲份,顯示洲份和至少有1000萬人(10,000,000)口國家的數(shù)目。
Select continent,count(name)from world
Wherepopulation>=10000000
GROUP BY continent
8.
列出有至少100百萬(1億)(100,000,000)人口的洲份。
Select continentfrom world
Group by continent
havingsum(population)>=100000000