Tuesday, September 10, 2024

SQL Subqueries

I analyzed a Database for answering questions of Deforestation.

There are 3 tables, forest_area, land_area and regions.

forest_area gives info about forest area for each country.

land_area is the land_area for each country.

and regions show which region each country belongs to.

forest_area and land_area have info for 1990 and 2016 years for each country.


I made a view of all the tables joined to figure out its structure:


This is the result:


That view is used by many queries so it is good to have it as another table.


I made a Subquery,

I first calculated the percentage of forest area relative to land area for all countries in 2016:

Then I grouped them by percent quartiles:

Counting the ocurrences on each group.


This is the result:



No comments:

Post a Comment