0% found this document useful (0 votes)
8 views3 pages

Copy of Day 5 - Solution

The document contains a series of SQL queries designed to extract various data from a database related to countries, languages, populations, and cities. Key queries include displaying country codes for multilingual countries, total world population, continent statistics, and specific details about cities and countries based on language and population criteria. Additionally, it outlines the creation of a new table for water resources and the insertion of data for Egypt.

Uploaded by

ahmed hussein
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Copy of Day 5 - Solution

The document contains a series of SQL queries designed to extract various data from a database related to countries, languages, populations, and cities. Key queries include displaying country codes for multilingual countries, total world population, continent statistics, and specific details about cities and countries based on language and population criteria. Additionally, it outlines the creation of a new table for water resources and the insertion of data for Egypt.

Uploaded by

ahmed hussein
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1- Display country code for all those speak more than 2 languages.

(149 rows)
select countrycode
from CountryLanguage
group by countrycode
having count(*) > 2

2- Display the number of people on earth.


select sum([population])
from Country
select sum(cast (population as bigint))
from Country

3- Display all Continents along with the number of countries and total population
in each continent. (7 rows)
select Continent, count(*), sum([population])
from Country
group by Continent
4- Display all cities that belong to Egypt. (37 row)
select *
from [dbo].[City]
where CountryCode in
(select Code from Country where Name = 'Egypt')

5- Display all countries that have cities with population more than 5 million.
(18 row)
select *
from [dbo].[Country]
where Code in
(select CountryCode from City where Population > 5000000)

6- Display all countries that speak “Dutch” as a secondary language. (1 row)


select *
from [dbo].[Country]
where Code in
(select CountryCode from CountryLanguage where
[Language]='Dutch' and IsOfficial = 'False')
7- Display all countries names along with their official language. (236 row)
select Name, [Language]
from [dbo].[Country], CountryLanguage
where Code = CountryCode and IsOfficial = 'True'

8- Display all cities that have the same district name. (51014 row)
select L.Name, R.Name
from City L, City R
where L.District = R.District and L.Name != R.Name

9- Display African countries names along with number of cities in each country.
(58 row)
select C.Name, count(*)
from Country C, City Cy
where Code = CountryCode and Continent = 'Africa'
group by C.Name

10- Display countries names with number of non-official languages. (201 row)

select Name, count(*)


from Country, CountryLanguage
where Code = CountryCode and IsOfficial = 'False'
group by Name

11- Display countries names who has more than one official language. (37 row)
select Name, count(*)
from Country, CountryLanguage
where Code = CountryCode and IsOfficial = 'True'
group by Name
having count(*) > 1

12- Display the most country whose inhabitants are expected to die early. (1 row)
select *
from Country
where LifeExpectancy in
(select min(LifeExpectancy) from Country)
13-Display countries names with number of cities only if its cities population
exceed 100 million. (2 row)
select C.Name, count(*)
from Country C, City Cy
where Code = CountryCode
group by C.Name
having sum(Cy.Population) > 100000000

14- Display country with the highest city population. (1 row)


select *
from Country
where code in
(select countryCode from City where Population =
(select Max(Population) from City))

15- Create new table “WaterResource” containing water resources for different
countries. The table must have the following fields:
● ID
● CountryCode.
● Type (e.g.: River, Sea, Ocean, Channel….etc.)
● Name.
16- Insert data in the created table for Egypt.

You might also like