You have a table and you want to find the minimum or maximum value of a column in that table. Here we have a country table and we want to find the minimum and maximum value of the
LifeExpectancy column or we want to find the minimum and maximum
LifeExpectancy value by continents.
To find the minimum value in a column we use the MIN() function and for maximum value we use the MAX() function.
SELECT MIN(LifeExpectancy) as min_LifeExp, MAX(LifeExpectancy) as max_LifeExp FROM country
To find the minimum and maximum life expectancy by continent, we have to first group the data by GROUP BY clause and then Apply the MIN() and MAX() function.
SELECT Continent, MIN(LifeExpectancy) as min_LifeExp, MAX(LifeExpectancy) as max_LifeExp FROM country GROUP BY Continent
If you like this post then please share it with others and subscribe to our blog below to learn data science.