我试图回答来自WORLD教程中的SELECT的SQLZoo上的#12,(http://sqlzoo.net/wiki/SQLZOO:SELECT_from_WORLD_Tutorial)
它要求"显示名称和大陆 - 但用欧亚大陆代替欧洲和亚洲;替代美国 - 北美或南美洲或加勒比地区的每个国家。显示以A或B"
开头的国家/地区我是SQL新手,似乎无法解决这个问题。请有人帮我解释一下如何解决这个问题?我大多陷入CASE陈述以及如何为条件做多个值。
提前谢谢!
答案 0 :(得分:0)
我不知道这是否是最佳方式,但希望有所帮助
select name,
Replace(continent,
case
when continent in('North America', 'South America', 'Caribbean', 'Europe', 'Asia') then continent
else '' end,
case
when continent in('Europe', 'Asia') then 'Eurasia'
when continent in('North America', 'South America', 'Caribbean') then 'America'
else '' end) as continent
from World where name like 'A%' or name like 'B%';
答案 1 :(得分:0)
SELECT
name as Name,
CASE WHEN continent IN ('Europe', 'Asia') THEN 'Eurasia'
WHEN continent IN ('North America', 'South America', 'Caribbean') THEN 'America'
ELSE continent END as Continent
FROM world
WHERE name BETWEEN 'A' AND 'C'
答案 2 :(得分:0)
SELECT name,
CASE WHEN continent IN ('Europe', 'Asia') THEN 'Eurasia'
WHEN continent IN ('North America', 'South America') THEN 'America'
WHEN continent = 'Caribbean' THEN 'America'
ELSE continent END
FROM world
WHERE name LIKE 'A%'
OR name LIKE 'B%'
答案 3 :(得分:0)
解决方案是:
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%'
答案 4 :(得分:-1)
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%'