
DAY2练习
SELECT from WORLD Tutorial:https://sqlzoo.net/wiki/SQLZOO:SELECT_from_WORLD_Tutorial/zh
BBC QUIZ:https://sqlzoo.net/wiki/BBC_QUIZ/zh
SELECT from Nobel Tutorial:https://sqlzoo.net/wiki/SELECT_from_Nobel_Tutorial/zh
Nobel Quiz:https://sqlzoo.net/wiki/Nobel_Quiz/zh
--SELECT from WORLD Tutorial--1selectname,continent,populationfrom world;--2selectnamefrom worldwhere population >= 200000000;--3selectname,GDP/population as per capita GDPfrom worldwhere population >= 200000000;--4selectname,population/1000000from worldwhere continent = 'South America';--5selectname,populationfrom worldwhere name in ('France','Germany','Italy');--6select namefrom worldwhere name like '%United%';--7selectname,population,areafrom worldwhere area > 3000000or population > 250000000;--8selectname,population,areafrom worldwhere (area > 3000000and population < 250000000)or (area < 3000000and population > 250000000);--9selectname,round(population/1000000,2),round(GDP/1000000000,2)from worldwhere continent = 'South America';/*这道题按照中文翻译会报错,英文中写明了“both”,GDP和population都要保留两位小数*/--10selectname,round(GDP/population,-3) as perfrom worldwhere GDP >= 1000000000000;--11selectname,capitalfrom worldwhere length(name) = length(capital);--12selectname,capitalfrom worldwhere left(name,1) = left(capital,1)and name != capital;/*其他解法*/selectname,capitalfrom worldwhere left(name,1) = left(capital,1)and name <> capital;--13select namefrom worldwhere length(name) - length(replace(name,'a','')) = 1and length(name) - length(replace(name,'e','')) = 1and length(name) - length(replace(name,'i','')) = 1and length(name) - length(replace(name,'o','')) = 1and length(name) - length(replace(name,'u','')) = 1and name not like '% %' ;/*注意题中要求每个元音字母仅有一个,划重点,然鹅有些错误答案居然也会显示correct answer,毕竟符合条件的只有Mozambique*/--SELECT from Nobel Tutorial--1select *from nobelwhere yr = 1950;--2select winnerfrom nobelwhere yr = 1962and subject = 'Literature';--3selectyr,subjectfrom nobelwhere winner = 'Albert Einstein';--4select winnerfrom nobelwhere yr >= 2000and subject = 'Peace';--5select *from nobelwhere yr between 1980 and 1989and subject = 'Literature';--6select *from nobelwhere winner in ('Theodore Roosevelt','Woodrow Wilson','Jimmy Carter');--7select winnerfrom nobelwhere winner like 'John%';--8select *from nobelwhere (yr = 1980and subject = 'physics')or (yr = 1984and subject = 'chemistry');/*再次温馨提示看英文的,中文翻译不准确*/--9select *from nobelwhere yr = 1980and subject != 'Chemistry'and subject != 'Medicine';/*其他解法*/select *from nobelwhere yr = 1980and subject <> 'Chemistry'and subject <> 'Medicine';/*其他解法*/select *from nobelwhere yr = 1980and subject not in ('Chemistry','Medicine');--10select *from nobelwhere (subject = 'Medicine'and yr < 1910)or (subject = 'Literature'and yr >= 2004);/*注意 together with*/--11select *from nobelwhere winner = 'PETER GRÜNBERG';--12select *from nobelwhere winner = 'EUGENE O''NEILL';--13selectwinner,yr,subjectfrom nobelwhere winner like 'Sir%'order by yr desc,winner;/*为啥没用select *,因为排列顺序和答案不一致会报错!*/--14selectwinner,subjectfrom nobelwhere yr = 1984order by subject in ('Chemistry','Physics'),subject,winner;/*subject为Chemistry和Physics,值为1(排在最后),否则为o(排在最前)*/
文章转载自EGG IXD,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




