MySQL实战训练一:错题集

1. Show the name - but substitute Australasia for Oceania - for countries beginning with N.

显示以N开头的国家并且用Australasia代替Oceania

答案:SELECT name, CASE WHEN continent='Oceania' THEN 'Australasia ELSE continent END  FROM world WHERE name LIKE 'N%';

2. 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 world 

WHERE name LIKE 'A%' OR name LIKE 'B%'

用到的关键语法,替换:CASE WHEN ... THEN ... WHEN... THEN... ELSE... END 

3. 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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,488评论 0 10
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 10,081评论 0 23
  • 在http://sqlzoo.net这个网站练习了sql语句,发现很多不会的语句,现记录在下面,便于复习: 1.修...
    qing00xin阅读 3,144评论 0 0
  • 三行情诗| 念 (文/亦浓) 1. 想好了不再理你 看到了你的信息 却忍不住泪流成河 2. 遇到你之前 我不知道 ...
    开在夜里的花儿阅读 604评论 16 11
  • 在我家里摆放着一台老钟,它是我母亲出嫁时带过来的嫁妆,摆在我家里已经有好几个年头了。尽管已经过去了这么多年,...
    温润如玉KK阅读 974评论 2 6