sqlzoo练习答案1

一.SELECT from WORLD

8.Exclusive OR (XOR). Show the countries that are big by area or big by population but not both. Show name, population and area.

SELECT name,population,area FROM world

WHERE area>3000000 XOR population>250000000

9.For South America show population in millions and GDP in billions both to 2 decimal places.

SELECT name,round(population/1000000,2) as population,round(gdp/1000000000,2) as gdp FROM world

WHERE continent='South America'

10.Show per-capita GDP for the trillion dollar countries to the nearest $1000.

SELECT name,round(gdp/population,-3) FROM world

WHERE gdp>=1000000000000

11.Show the name and capital where the name and the capital have the same number of characters.

SELECT name,capital FROM world

WHERE LENGTH(name)=LENGTH(capital)

12.Show the name and the capital where the first letters of each match. Don't include countries where the name and the capital are the same word.

SELECT name,capital FROM world
WHERE LEFT(name,1)=LEFT(capital,1)

AND name<>capital

13.

Equatorial Guinea and Dominican Republic have all of the vowels (a e i o u) in the name. They don't count because they have more than one word in the name.

Find the country that has all the vowels and no spaces in its name.

SELECT name FROM world WHERE name like '%a%' and name like'%e%' and name like '%i%' and name LIKE '%o%' and name LIKE '%u%' AND name NOT LIKE '% %'

二.SELECT from Nobel

10.Show year, subject, and name of people who won a 'Medicine' prize in an early year (before 1910, not including 1910) together with winners of a 'Literature' prize in a later year (after 2004, including 2004)

select yr,subject,winner from nobel
where (subject='Medicine' and yr<1910)

or (subject='Literature' and yr>=2004)

12.Find all details of the prize won by EUGENE O'NEILL

select * from nobel

where winner='EUGENE O''NEILL'

14.

The expression subject IN ('Chemistry','Physics') can be used as a value - it will be 0 or 1.

Show the 1984 winners and subject ordered by subject and winner name; but list Chemistry and Physics last.

SELECT winner, subject
FROM nobel
WHERE yr=1984
ORDER BY subject IN ('Physics','Chemistry'),subject,winner

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值