gpt4 book ai didi

sql - sqlzoo 上 'select from world' 教程第 13 部分的解决方案是什么?

转载 作者:行者123 更新时间:2023-12-04 16:24:17 33 4
gpt4 key购买 nike

problem statement是:

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 ('Europe', 'Asia') THEN 'Europe/Asia'
WHEN name='Turkey' THEN 'Europe/Asia'
WHEN continent='Caribbean' AND name LIKE 'B%' THEN 'North America'
WHEN continent='Caribbean' AND name NOT LIKE 'B%' THEN 'South America'
ELSE continent END
FROM world

我从 sqlzoo 得到的结果是“答案错误。有些数据不正确。”。

最佳答案

这对我有用。不要问我为什么必须使用 ORDER BY(没有它就行不通)。

SELECT name, continent,
CASE WHEN continent='Oceania' THEN 'Australasia'
WHEN continent = 'Eurasia' THEN 'Europe/Asia'
WHEN name='Turkey' THEN 'Europe/Asia'
WHEN continent='Caribbean' AND name LIKE 'B%' THEN 'North America'
WHEN continent='Caribbean' AND name NOT LIKE 'B%' THEN 'South America'
ELSE continent END
FROM world ORDER BY name

关于sql - sqlzoo 上 'select from world' 教程第 13 部分的解决方案是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30195610/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com