Copy of Day 5 - Solution
Copy of Day 5 - Solution
(149 rows)
select countrycode
from CountryLanguage
group by countrycode
having count(*) > 2
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)
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)
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
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.