Country Profiles: Name Region Area Population GDP
Country Profiles: Name Region Area Population GDP
Exercises
Using the SELECT statement.
1a. Read the notes about this table. Issue the command: SELECT name, Results
region, population FROM bbc. Look at the output.
Before attempting the following questions read this! How to use WHERE to filter
records.
2a. Show the name for the countries that have a population of at least Results
200 million. (200 million is 200000000, there are eight zeros)
2b. Give the name and the per capita GDP for those countries with a Results
population of at least 200 million.
HELP:How to calculate per capita GDP
2c. Show the name and population in millions for the countries of 'Middle Results
East'
Divide the population by 1000000 to get population in millions.
2d. Show the name and population for 'France', 'Germany', 'Italy' Results
2e. Identify the countries which have names including the word 'United'
Exercises
Using the SELECT statement.
nobel
yr subject winner
1960 Chemistry Willard F. Libby
1960 Literature Saint-John Perse
1960 Medicine Sir Frank Macfarlane Burnet
1960 Medicine Peter Medawar
1a. Change the query shown so that it displays Nobel prizes for 1950. Results
1b. Show who won the 1962 prize for Literature. Results
2a. Show the year and subject that won 'Albert Einstein' his prize. Results
2b. Give the name of the 'Peace' winners since the year 2000, including Results
2000.
2c. Show all details (yr, subject, winner) of the Literature prize winners Results
for 1980 to 1989 inclusive.
2d. Show all details of the presidential winners: ('Theodore Roosevelt', Results
'Woodrow Wilson', 'Jed Bartlet', 'Jimmy Carter')
2e. Show the winners with first name John Results
3a. In which years was the Physics prize awarded but no Chemistry prize.
(WARNING - this question is way too hard for this level, you will need to
use sub queries or joins).
Exercises
Using nested SELECT.
1a. List each country name where the population is larger than 'Russia'. Results
1b. List the name and region of countries in the regions containing 'India', Results
'Iran'.
1c. Show the countries in Europe with a per capita GDP greater than Results
'United Kingdom'.
Per Capita GDP
1d. Which country has a population that is more than Canada but less than Results
Algeria?
To get a well rounded view of the important features of SQL you should move on to
the next tutorial concerning aggregates.
To gain an absurdly detailed view of one insignificant feature of the language, read
on.
We can use the word ALL to allow >= or > or < or <=to act over a list.
2a. Which countries have a GDP greater than any country in Europe? Results
[Give the name only.]
We can refer to values in the outer SELECT within the inner SELECT. We can name
the tables so that we can tell the difference between the inner and outer versions.
3b. Find each country that belongs to a region where all populations are Results
less than 25000000. Show name, region and population.
3c. Some countries have populations more than three times that of any of Results
their neighbours (in the same region). Give the countries and regions.
Exercises
Using SUM, COUNT, MAX, AVG, DISTINCT and ORDER BY.
2a. For each region show the region and number of countries. Results
2b. For each region show the region and number of countries with Results
populations of at least 10 million.
2c. List the regions with total populations of at least 100 million. Results
What next
The nobel table can be used to practice more SUM and COUNT functions
The next tutorial is looks at the Table Tennis database. It shows how queries may use
records from two related tables.
SELECT
Building queries
Specific to Oracle
none
Related links:
SELECT
o Concatenate two or more fields.
o Make union between different tables to build one single view or
request?
o Use 'like' in a sql select statement
o How to build a statement on a word with an Apostrophe such as
WHERE name='Tom's Book'
o Full text search
o Display a column name for an aggregate function.
o How do you use Equi Join to join two tables with the same name.
o Use SELECT for a column whose name contains spaces.
o use NULL
o
o Use 'like' in a sql select statement
o How to build a statement on a word with an Apostrophe such as
WHERE name='Tom's Book'
o Full text search
o Display a column name for an aggregate function.
o How do you use Equi Join to join two tables with the same name.
o Use SELECT for a column whose name contains spaces.
o use NULL
How to build a statement on a word with an Apostrophe such as WHERE
name='Tom's Book'
Specific to Oracle
Use two apostrophes.
Related links:
SELECT
o Concatenate two or more fields.
o Make union between different tables to build one single view or
request?
o Use 'like' in a sql select statement
o How to build a statement on a word with an Apostrophe such as
WHERE name='Tom's Book'
o Full text search
o Display a column name for an aggregate function.
o How do you use Equi Join to join two tables with the same name.
o Use SELECT for a column whose name contains spaces.
o use NULL
Full text search
Display a column name for an aggregate function.
How do you use Equi Join to join two tables with the same name.
Use SELECT for a column whose name contains spaces.
use NULL
DATES
How to work with dates; adding, subtracting and formatting.