Aggregates in SQL
SQL (Structured Query Language) is a powerful tool for querying and analyzing data stored in relational databases. In this beginner-friendly guide, we'll dive into the fascinating world of SQL queries using a sample database containing information about countries and continents. By exploring various SQL queries, we'll uncover insights about global population, GDP, area, and more.
Show the total population of the world.
SELECT SUM(population)
FROM world
List all the continents - just once each.
SELECT DISTINCT continent
FROM world;
Give the total GDP of Africa
SELECT SUM(gdp) FROM world
WHERE continent='Africa'
How many countries have an area of at least 1000000
SELECT COUNT(name) FROM world
WHERE area > 1000000
What is the total population of ('Estonia', 'Latvia', 'Lithuania')
SELECT SUM(population) FROM world
WHERE name IN('Estonia', 'Latvia', 'Lithuania')
For each continent show the continent and number of countries.
SELECT continent,count(name) FROM world
GROUP BY continent
For each continent show the continent and number of countries with populations of at least 10 million.
SELECT continent,count(name) FROM world
WHERE population > 10000000
GROUP BY continent
List the continents that have a total population of at least 100 million.
SELECT continent FROM world
GROUP BY continent
HAVING SUM(population) > 100000000
SQL queries offer a versatile way to extract valuable insights from large datasets. In this guide, we've covered a range of queries to explore world data, from summarizing population and GDP to analyzing country demographics by continent. As you continue your journey with SQL, remember that practice is key to mastering this essential skill in data analysis and database management. Happy querying!
Message ChatGPT
ChatGPT can make mistakes. Check important info.
?