当前位置:网站首页>SQLZOO——SELECT from WORLD Tutorial
SQLZOO——SELECT from WORLD Tutorial
2022-07-23 04:23:00 【橙子教师】

In this tutorial you will use the SELECT command on the table world:
注意:world表定义如下:

Introduction
1.
Read the notes about this table. Observe the result of running this SQL command to show the name, continent and population of all countries.
SELECT name,continent,population
FROM world
Large Countries
2.
How to use WHERE to filter records. Show the name for the countries that have a population of at least 200 million. 200 million is 200000000, there are eight zeros.
SELECT name
FROM world
WHERE population >= 200000000
Per capita GDP
3.
Give the name and the per capita GDP for those countries with a population of at least 200 million.
HELP:How to calculate per capita GDP
SELECT name,gdp/population as per_capita_GDP
FROM world
WHERE population >= 200000000
South America In millions
4.
Show the name and population in millions for the countries of the continent 'South America'. Divide the population by 1000000 to get population in millions.
select name,population/1000000 as population_millions
from world
where continent = 'South America'
France, Germany, Italy
5.
Show the name and population for France, Germany, Italy
select name,population
from world
where name in ('France', 'Germany', 'Italy')
United
6.
Show the countries which have a name that includes the word 'United'
select name
from world
where name like '%United%'
Two ways to be big
7.
Two ways to be big: A country is big if it has an area of more than 3 million sq km or it has a population of more than 250 million.
Show the countries that are big by area or big by population. Show name, population and area.
select name,population,area
from world
where area >= 3000000 or population >= 250000000
One or the other (but not both)
8.
Exclusive OR (XOR). Show the countries that are big by area (more than 3 million) or big by population (more than 250 million) but not both. Show name, population and area.
- Australia has a big area but a small population, it should be included.
- Indonesia has a big population but a small area, it should be included.
- China has a big population and big area, it should be excluded.
- United Kingdom has a small population and a small area, it should be excluded.
select name,population,area
from world
where (area >= 3000000 and population < 250000000) or (area < 3000000 and population >= 250000000)
Rounding
9.
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
select name,round(population/1000000,2) as population_millions,round(gdp/1000000000,2) as gdp_billions
from world
where continent ='South America'
Trillion dollar economies
10.
Show the name and per-capita GDP for those countries with a GDP of at least one trillion (1000000000000; that is 12 zeros). Round this value to the nearest 1000.
Show per-capita GDP for the trillion dollar countries to the nearest $1000.
select name, round(gdp/population,-3) as per_capita_GDP
from world
where gdp>1000000000000
Name and capital have the same length
11.
Greece has capital Athens.
Each of the strings 'Greece', and 'Athens' has 6 characters.
Show the name and capital where the name and the capital have the same number of characters.
- You can use the LENGTH function to find the number of characters in a string
select name,capital
from world
where length(name) = length(capital)
Matching name and capital
12.
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
All the vowels
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.
- 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 '% %'
边栏推荐
- 配饰器模式
- 数据湖:从数据仓库看数据湖
- mysql通过sql查询数据库所有表名称及列信息
- Registration tree mode
- Unity Image中Sprite和overrideSprite区别(转载)
- 8 < tag dynamic programming and LCS problems > lt.300. Longest increasing subsequence + lt.674. Longest continuous increasing sequence
- Cs5266+ma8621 do the scheme design of typec to hdmi+pd+u3+2u+sd/tf seven in one expansion dock | cs5266 multi port expansion dock pcb+ schematic diagram reference
- 【Qt5.12】Qt5.12安装教程
- What is the difference between College coder and 985 programmer?
- 振奋人心 元宇宙!下一代互联网的财富风口
猜你喜欢

仅用5000行代码,在V853上AI渲染出一亿幅山水画

HoloLens第三视角开发【保姆级教程】【踩坑记录】

振奋人心 元宇宙!下一代互联网的财富风口

Kingbasees SQL language reference manual of Jincang database (8. Function (7))

Redis installation

What is instant messaging? Development of instant messaging

Self operation and maintenance: a new sample of it operation and maintenance services in Colleges and Universities

Rapid SQL All-Platforms高性能 SQL 代码

ANTLR4 入门学习(一):下载和测试

Network data leakage events occur frequently, how to protect personal privacy information?
随机推荐
科技赋能新保险:中华财险的数字化转型
Redis transaction - detailed implementation process of seckill case simulation
22. Notes on the use of combobox in WPF
Redis pseudo cluster one click deployment script - pro test available
Kingbasees SQL language reference manual of Jincang database (8. Function (I))
元宇宙浪潮震撼来袭,抓住时机,齐心协力
32 < tag array and bit operation > supplement: Lt. sword finger offer 56 - I. number of occurrences of numbers in the array
LeetCode每日一题(1946. Largest Number After Mutating Substring)
Network data leakage events occur frequently, how to protect personal privacy information?
CLion + MinGW64配置C语言开发环境 Visual Studio安装
Add trust list
NFT数字藏品版权如何保护?
Redis安装
Redis installation
After 100 billion of revenue, Alibaba cloud ecosystem has a new way to play
MySQL主从复制
AI性能拉满的“广和通AI智能模组SCA825-W”加速推进电商直播2.0时代
《Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks》论文阅读
智慧园区的核心本质是什么?
什么是文件管理软件?你为什么需要它?