Skip to content
Exploratory Data Analysis in SQL for Absolute Beginners
Query the table
- Query the full table
DataFrameavailable as
df
variable
SELECT *
FROM climate
- Query the
country
andwater_stress_index
fields and order by descending order of thewater_stress_index
field
DataFrameavailable as
df
variable
SELECT country, water_stress_index
FROM climate
ORDER BY water_stress_index DESC;
- Query the
country
,year
, andgdp_per_capita
field to get a list of the country names and their respective GDP; order by the GDP in ascending order but only view the top 10 values
DataFrameavailable as
df
variable
SELECT country, year, gdp_per_capita
FROM climate
ORDER BY gdp_per_capita ASC
LIMIT 10;
Filter the data
- Filter the data to see the
country
andyear
where thewater_stress_index
was between0.5
and0.6
DataFrameavailable as
df
variable
SELECT country, year, water_stress_index
FROM climate
WHERE water_stress_index BETWEEN 0.5 AND 0.6;
- This time, filter the data to see the countries that start with the letter
E
orS
and have awater_stress_index
above0.5
DataFrameavailable as
df
variable
SELECT country, water_stress_index
FROM climate
WHERE water_stress_index > 0.5 AND (country LIKE 'S%' OR country LIKE 'E%');
Aggregate, group, and sort the data