【练习篇】SQLZOO(中文版)习题答案_SELECT from world
SELECT from WORLD Tutorial/zh
1.閱讀此表的注意事項 觀察運行一個簡單的SQL命令的結(jié)果。
2.如何使用WHERE來篩選記錄。 顯示具有至少2億人口的國家名稱。 2億是200000000,有八個零。
SELECT name FROM world WHERE population>2000000003.找出有至少200百萬(2億)人口的國家名稱,及人均國內(nèi)生產(chǎn)總值。求助:如何人均國內(nèi)生產(chǎn)總值計算人均國內(nèi)生產(chǎn)總值,即是國內(nèi)生產(chǎn)總值除以人口(GDP/population)。
SELECT name,gdp/population FROM world WHERE population>200000000重點:
4.顯示’South America’南美洲大陸的國家名字和以百萬為單位人口數(shù)。 將人口population 除以一百萬(1000000)得可得到以百萬為單位人口數(shù)。
5.顯示法國,德國,意大利(France, Germany, Italy)的國家名稱和人口。
SELECT name,population FROM world WHERE name IN ('France','Germany','Italy')注意:數(shù)據(jù)過濾有取值范圍用IN;
6.顯示包含單詞“United”為名稱的國家。
SELECT name FROM world WHERE name LIKE '%United%'注意:
1.對國家名稱進行篩選,這里是模糊查詢要用LIKE,不能用等號;
2.通配符%表示任何字符,任意數(shù)目(包括0個)
7.成為大國的兩種方式:如果它有3百萬平方公里以上的面積,或擁有250百萬(2.5億)以上人口。展示大國的名稱,人口和面積。
SELECT name,population,area FROM world WHERE population>250000000 or area>30000008.美國、印度和中國(USA, India, China)是人口又大,同時面積又大的國家。排除這些國家。顯示以人口或面積為大國的國家,但不能同時兩者。顯示國家名稱,人口和面積。
SELECT name,population,area FROM world WHERE (population>250000000 AND area<3000000) or (population<250000000 AND area>3000000)9.除以為1000000(6個零)是以百萬計。除以1000000000(9個零)是以十億計。使用 ROUND 函數(shù)來顯示的數(shù)值到小數(shù)點後兩位。對於南美顯示以百萬計人口,以十億計2位小數(shù)GDP。
SELECT name, ROUND(population/1000000,2), ROUND(gdp/1000000000,2) FROM world WHERE continent='South America'10.顯示國家有至少一個萬億元國內(nèi)生產(chǎn)總值(萬億,也就是12個零)的人均國內(nèi)生產(chǎn)總值。四捨五入這個值到最接近1000。顯示萬億元國家的人均國內(nèi)生產(chǎn)總值,四捨五入到最近的$ 1000。
SELECT name,ROUND(gdp/population/1000)*1000 FROM world WHERE gdp>=1000000000000;11.The CASE statement shown is used to substitute North America for Caribbean in the third column.Show the name - but substitute Australasia for Oceania - for countries beginning with N.
SELECT name, CASE WHEN continent='Oceania' THEN 'Australasia' ELSE continent END FROM world WHERE name LIKE 'N%'12.Show the name and the continent - but substitute Eurasia for Europe and Asia; substitute America - for each country in North America or South America or Caribbean. Show countries beginning with A or B
SELECT name, CASE WHEN continent IN('Europe','Asia') THEN 'Eurasia' WHEN continent IN('North America','South America','Caribbean')THEN 'America' ELSE continent END FROM worldWHERE name LIKE 'A%' OR name LIKE 'B%'13.Put the continents right…
● Oceania becomes Australasia
● Countries in Eurasia and Turkey go to Europe/Asia
● Caribbean islands starting with ‘B’ go to North America, other Caribbean islands go to South AmericaShow the name, the original continent and the new continent of all countries.
總結(jié)
以上是生活随笔為你收集整理的【练习篇】SQLZOO(中文版)习题答案_SELECT from world的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 相思会有病
- 下一篇: 梅科尔工作室-崔启凡-鸿蒙笔记3