1. 程式人生 > >SQLZOO網頁中SQL的答案

SQLZOO網頁中SQL的答案

開頭 and title with div asc asi trie ont

SELECT from world篇


11.

題目:

The CASE statement shown is used to substitute North America forCaribbean in the third column.

Show the name - but substitute Australasia for Oceania - for countries beginning with N. (翻譯:讓你給出名字和所屬大洲的名字, 其中所屬大洲的名字是Oceania的改成Australasia, 條件是國名的第一個字符是N) 答案: SELECT name, CASE WHEN continent=‘Oceania‘ THEN ‘Australasia‘ ELSE continent END FROM world WHERE name LIKE ‘N%‘; 解答: CASE有點想IF THEN語句。
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 (翻譯:顯示name,continent 要求當continent為Asia和Europe時,修改continent為Eurasia。 當continent為North America或South America或Caribbean時,修改為America. 條件是name以A或B開頭) 答案:

SELECT name,
CASE WHEN continent IN (‘Asia‘,‘Europe‘) THEN ‘Eurasia‘
WHEN continent IN (‘North America‘,‘South America‘,‘Caribbean‘) THEN ‘America‘
ELSE continent END
FROM world
WHERE name LIKE ‘A%‘ OR name LIKE ‘B%‘


答案:

SELECT name,continent,
CASE WHEN continent IN (‘Eurasia‘, ‘Turkey‘)
THEN ‘Europe/Asia‘

WHEN continent = ‘Oceania‘
THEN ‘Australasia‘

WHEN continent = ‘Caribbean‘
THEN
CASE
WHEN name LIKE ‘B%‘
THEN ‘North America‘
ELSE ‘South America‘
END
ELSE continent
END
FROM world
ORDER BY name ASC;

SQLZOO網頁中SQL的答案