http://sqlzoo.net/wiki/SELECT_from_WORLD_Tutorial
1增拥、select name,continent,population from world
2谴垫、select name from world
where population>200000000
3皆怕、select name,gdp/population from world
where population>200000000
4抡诞、select name,population/1000000
from world
where continent like 'south america'
5炕桨、select name,population
from world
where name in ('france','germany','italy')
6丧凤、select name from world
where name like '%united%'
7、select name,population,area
from world
where population>250000000 orarea>3000000
8俘陷、select name,population,area?
from world
where (area>3000000 andpopulation<250000000) or (area<3000000 and population>250000000)
說明:根據(jù)上題所示罗捎,area>3000000或population>250000000的即為big country,則逆向思維拉盾,可理解為area<3000000且population>250000000為big country桨菜;或者area>3000000且population<250000000也為big country。
9捉偏、select name,ROUND(population/1000000,2),ROUND(gdp/1000000000,2)?
from world
where continent='south america'
說明:
·函數(shù)ROUND的應(yīng)用倒得。ROUND(number,digits)即round(數(shù)字,需要保留的小數(shù)點(diǎn)位數(shù))夭禽。Digits表示對(duì)小數(shù)點(diǎn)左側(cè)或者右側(cè)進(jìn)行四舍五入霞掺。當(dāng)digits為正數(shù),則保留幾位小數(shù)點(diǎn)驻粟;當(dāng)digits為0根悼,則表示取整數(shù);當(dāng)digits為負(fù)數(shù)蜀撑,則表示對(duì)小數(shù)點(diǎn)左邊的整數(shù)部分進(jìn)行四舍五入挤巡。
·例如Round(930.256897,-2)=900酷麦;Round(930.256897矿卑,-3)=1000;Round(930.256897沃饶,2)=930.26母廷;Round(930.256897,0)=930糊肤∏倮ィ可在excel函數(shù)公式中中試驗(yàn)。
·?millions (百萬)即為 字段 除以1000000
·billions(數(shù)十億)即為字段除以1000000000
10馆揉、select name,round(gdp/population,-3)
from world
where gdp>1000000000000
說明:round函數(shù)的應(yīng)用业舍。原題要求四舍五入到1000,即整數(shù)部分到千位升酣。
人均GDP的計(jì)算公式為GDP除以人口數(shù)舷暮,即GDP/POPULATION
11、SELECT name,capital
from world
where length(name)=length(capital)
說明:當(dāng)一個(gè)國(guó)家的名字和首都名字的字符數(shù)相同噩茄,則篩選查詢顯示出來下面。
Length()意為返回括號(hào)內(nèi)字符串的個(gè)數(shù)。括號(hào)內(nèi)的字符串不加單引號(hào)绩聘。
12沥割、
select name,capital
from world
where left(name,1)=left(capital,1) andname<>capital
或selectname,capital
from world
where left(name,1)=left(capital,1) andname!=capital
說明:原題意要求國(guó)家名稱和首都名稱第一個(gè)字母相同耗啦,但是國(guó)家名稱和首都名稱不能完全相同。函數(shù)left(text驯遇,第幾個(gè)數(shù)字)即獲取文本或字段的第幾個(gè)字符芹彬。符號(hào)“<>”表示不等于,同時(shí)“叉庐!=”也表示不等于。
13会喝、原題“Find the country that has all the vowels(a e i o u)?and no spaces in itsname.”
包含(a e i o u)?且沒有空格陡叠??肢执?枉阵?
SELECT name FROM world WHERE name like '%a%' andname like'%e%' and name like'%i%' and name LIKE '%o%' and name LIKE '%u%' ANDname NOT LIKE '% %'