

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


--9. Create View Asian Rivers create view Asian_Rivers as (select distinct name, length from encompasses, river, geo_River where continent = 'Asia' and encompasses.country = geo_River.country and geo_River.river = river.name); -- 11. Adding population density column to the country table alter table country add pop_density real; -- 12. Adding population density data update country set pop_density = population / area; -- 13. Countries whose population desnsity differs -- by a factor of 10,000 or more select T.name, S.name from country T, country S where T.pop_density / S.pop_density > 10000; --14. 5th largest economy in the world select name, gdp, t.rank_seq from (select country, gdp, rank() over (order by gdp desc) rank_seq from economy where gdp >0) t, country where country.code = t.country and t.rank_seq = 5; -- 15. Countries that span more than one continent select name, T.continent, count(S.continent) from country, encompasses T, encompasses S where code = T.country and code = S.country and T.percentage < 100 group by name, T.continent; -- 16. Triggering addition of host country to -- membership of new organizations create or replace trigger New_organization_trigger after insert on Organization for each row begin insert into Is_member (Country, Organization, Type) values (:new.Country, :new.Abbreviation, 'host'); end ; / ; -- 17. Projected population of Australia in 2010 select c.Population* power(1+ p.Population_growth/100, 3) from Country c, Population p where p.Country = c.Code and c.Name = 'Australia'; -- 18. Euro_percentage table create table Euro_Percentage as with Europe_Population as (select sum(c.Population) E_pop from Country c, Encompasses e where c.Code = e.Country and e.Continent = 'Europe' group by e.Continent) select c.Name as Name, c.Population / Europe_Population.E_pop*100 as Percentage from Country c, Encompasses e, Europe_Population where c.Code = e.Country and e.Continent = 'Europe'; -- 19. Countries 3 hop away from Turkey create table hop1 (c1 varchar(32), c2 varchar(32));
create table hop2 (c1 varchar(32), c2 varchar(32)); create table hop3 (c1 varchar(32), c2 varchar(32)); insert into hop1 (select country1, country2 from borders, country where name = 'Turkey' and code = country1) union (select country2, country1 from borders, country where name = 'Turkey' and code = country2); insert into hop2 (select a.c1, b.country2 from hop1 a, borders b where a.c2 = b.country1 union (select a.c1, b.country1 from hop1 a, borders b where a.c2 = b.country2)); insert into hop3 (select hop2.c1, borders.country2 from hop2, borders where hop2.c2 = borders.country union (select hop2.c1, borders.country1 from hop2, borders where hop2.c2 = borders.country2)); select name from country, (select distinct c2 result from hop3 minus (select distinct c2 from hop2 union (select distinct c2 from hop1 union (select distinct c1 from hop1)))) where result = code; --20. Total population of Asia select sum(c.Population* e.Percentage/100) from Country c, Encompasses e where c.Code = e.Country and e.Continent = 'Asia' group by e.Continent;