中文題目
10.顯示國家有至少一個萬億元國內(nèi)生產(chǎn)總值(萬億,也就是12個零)的人均國內(nèi)生產(chǎn)總值。四捨五入這個值到最接近1000。
顯示萬億元國家的人均國內(nèi)生產(chǎn)總值,四捨五入到最近的$ 1000。
SELECT name,round(gdp/population,-3) FROM world
WHERE (gdp/1000000000000)> 1
這道題考round的用法-3表示整數(shù)位左移3位取0 即保留千位 1000
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 America
Show the name, the original continent and the new continent of all countries.
select name,continent,
case when continent ='Oceania' then 'Australasia'
when continent in ('Eurasia','Turkey') then 'Europe/Asia'
when continent ='Caribbean' then
case when name like 'B%' then 'North America'
else 'South America'
end
else continent end
from world
ORDER BY name
這道題考case when 以及其嵌套用法
英文題目
12 The capital of Sweden is Stockholm. Both words start with the letter 'S'.
Show the name and the capital where the first letters of each match. Don't include countries where the name and the capital are the same word.
- You can use the function LEFT to isolate the first character.
- You can use
<>
as the NOT EQUALS operator.
SELECT name, capital
FROM world
where LEFT(name,1) = LEFT(capital,1) and name <> capital
這道題考LEFT 函數(shù),函數(shù)用于從字符串的左側(cè)提取指定數(shù)量的字符。平時比較少用,可以注意一下。
13.Equatorial Guinea and Dominican Republic have all of the vowels (a e i o u) in the name. They don't count because they have more than one word in the name.
Find the country that has all the vowels and no spaces in its name.
You can use the phrase name NOT LIKE '%a%' to exclude characters from your results.
The query shown misses countries like Bahamas and Belarus because they contain at least one 'a'
SELECT name
FROM world
WHERE name LIKE '%a%'
AND name LIKE '%e%'
AND name LIKE '%i%'
AND name LIKE '%o%'
AND name LIKE '%u%'
AND name NOT LIKE '% %'