当前位置:网站首页>SQLZOO——SELECT from WORLD Tutorial
SQLZOO——SELECT from WORLD Tutorial
2022-07-23 10:42:00 【Orange teacher】

In this tutorial you will use the SELECT command on the table world:
Be careful :world The table is defined as follows :

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 '% %'
边栏推荐
- 应用层重要知识(面试、复试、期末)
- 8 < tag dynamic programming and LCS problems > lt.300. Longest increasing subsequence + lt.674. Longest continuous increasing sequence
- Unityc realizes the conversion of Chinese characters to Pinyin - using Microsoft chspinyinconv Library
- 2022/7/20
- Chapter 3 Standard Input
- 0基础转行软件测试,月薪6000和11000的必备技能,截然不同...
- What is the difference between College coder and 985 programmer?
- Introduction to partition operators, broadcast variables and accumulators of 32 spark
- Unity Image中Sprite和overrideSprite区别(转载)
- The difference between sprite and overridesprite in unity image (Reprint)
猜你喜欢

优化.NET 应用程序 CPU 和内存的11 个实践

Use the x2mindspire tool of mindstudio to convert training scripts

8 < tag dynamic programming and LCS problems > lt.300. Longest increasing subsequence + lt.674. Longest continuous increasing sequence
![【Warning】YOLOV5训练时的ignoring corrupt image/label: [Errno 2].....,无法全部训练数据集,快速带你解决它](/img/14/ac1a600ccdd3e7d4c8e5c64087648d.png)
【Warning】YOLOV5训练时的ignoring corrupt image/label: [Errno 2].....,无法全部训练数据集,快速带你解决它

Ultra Fast Deep Lane Detection with Hybrid Anchor Driven Ordinal Classification论文解读

中国经济网:“元宇宙”炙手可热

Antlr4 introductory learning (I): Download and test

What is file management software? Why do you need it?

Sequence model (2) - natural language processing and word nesting

Chapter 4: runtime data area - shared space
随机推荐
Interest rate in installment payment
Registration tree mode
Seektiger's okaleido has a big move. Will the STI of ecological pass break out?
Chapter 3 Standard Input
Flask learning notes
Visual Studio 2022有趣又强大的智能辅助编码
What is the core essence of smart parks?
网络安全等级保护2.0标准解析
Redis replication cluster setup
LeetCode刷题--点滴记录022
2022/7/20
Clion + mingw64 configure C language development environment visual studio installation
行业洞察|如何更好地建设数据中台?IT和业务要“齐步走”
DPDK 交叉编译基本流程
openvino_datawhale
Undo log details
Kingbasees SQL language reference manual of Jincang database (8. Function (III))
比你老师详细系列————结构体
MySQL master-slave replication
理解ASP.NET Core - 基于Cookie的身份认证(Authentication)