Simple SQL Queries
Create the country table described in the demonstration material in
you database management system.
Write SQL queries for the queries listed in following subsections.
Lab. 1) Selection and Projection
- List names from rows where name contains 'Ocean'.
- List all columns from rows where area is zero.
- List names of all regions. The list should not have any duplicates.
- List names of populous (i.e. population over 10 Million) countries.
- List names of populous (i.e. population over 10 Million)
European and Asian countries sorted by per capita GDP.
Lab. 2) Summarization, Aggregation
- Count number of countries with area between 0.5 Million Sq. Km. and 1
Million Sq. Km.
- List number of countries, total area, average area per country for all
regions of the world.
- Select regions which have at least 5 countries with population over 10
Million.
- List population, GDP, population density for regions of the world in
order of GDP.
- Create a histogram showing number of countries in following population
ranges of 10 Million.
Lab. 3) Nested queries
- Find names of countries with GDP more than the total GDP of Africa.
- Find the region with largest GDP. Do not use MAX. You will need SUM to
compute region totals.
- Find the countries in Asia with population larger than the largest
population of North American countries.
Lab. 4) Insert, update and delete
- Examine the rows with non-zero area but
zero gdp and population. Delete these rows assuming these do
not constitute countries.
- Determine the region for Mauritius.
Update region for Mauritius to be Africa.
- Update population of United States to reflect 5 percent increase per
year since 1995.
- Hong Kong merged with China in 1997.
Add the population, area, gdp of Hong Kong to China. Delete Hong Kong.
- Insert a new country, Korea in Asia region. Its area, population and gdp
are sum of each in two countries, 'Korea, North' and 'Korea, South'. Delete
'Korea, North' and 'Korea, South' countries.