SQLZOO练习1

练习内容:
  1. SELECT关键字
  2. ROUND函数
  3. LEFT函数
    在这里插入图片描述
ROUND函数

在这里插入图片描述
ROUND(x,n):四舍五入,x为四舍五入的数,n为位数
(1)位数 = 0,则四舍五入到整数
(2)位数 > 0,则四舍五入到指定的小数位
(3)位数 < 0,则在小数点左侧进行四舍五入

题目:
Show the name and population in millions and the GDP in billions for the countries of the continent ‘South America’. Use the ROUND function to show the values to two decimal places.

For South America show population in millions and GDP in billions both to 2 decimal places.
Millions and billions
Divide by 1000000 (6 zeros) for millions. Divide by 1000000000 (9 zeros) for billions.

SELECT name, ROUND(population/1000000,2), ROUND(gdp/1000000000,2)
 FROM world
WHERE continent  = 'South America'
LEFT函数

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
题目:
The capital of Sweden is Stockholm. Both words start with the letter ‘S’.

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.
You can use the function LEFT to isolate the first character.
You can use <> as the NOT EQUALS operator.

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

(不等也可用‘!=’)

通配符

题目:
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.
(国家名含有每个元音字母但不含空格)
You can use the phrase

name NOT LIKE ‘%a%’

to exclude characters from your results.
The query shown misses countries like Bahamas and Belarus because they contain at least one ‘a’

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 '% %'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值