A focused SQL analysis project using the World sample database (City & Country tables).
This repository showcases practical skills in data querying, joins, aggregation, and population-based analysis using MySQL.
The World Database.sql script contains a series of queries that explore:
- Global cities and their populations
- Countries, regions and continents
- Relationships between City and Country
- Ranking and filtering based on population metrics
The script works as a compact SQL practice workbook for geography-based data analysis.
- Data retrieval and exploration:
SELECT,WHERE,ORDER BY
- Pagination / result windowing:
LIMITandOFFSET
- Aliasing and readability improvements:
- Column aliases (e.g.
AS Total_Cities,AS City_Population)
- Column aliases (e.g.
- Conditional filtering on:
- Country codes
- Population thresholds
Using the World schema:
- Joining
countryandcityvia:country.Code = city.CountryCode
- Combining attributes from both tables, such as:
- Country name + city name
- Region + city population
These joins support queries like:
- Listing cities with their corresponding country
- Filtering cities by country or region
- Comparing populations across multiple countries
Using aggregate functions to answer questions such as:
- How many cities exist in a given country?
- What is the total population across selected cities or countries?
- Which cities are the largest by population?
Key functions used:
COUNT(ID)for city countsSUM(Population)for totalsAVG(Population)andMAX(Population)(where applicable)- Grouping with
GROUP BYonCountryCodeor country name
Representative examples based on the script contents.
SELECT COUNT(ID) AS Total_Cities
FROM City
WHERE CountryCode = 'USA';SELECT Name, Population
FROM City
ORDER BY Population DESC
LIMIT 10;SELECT
cty.Name AS City,
cty.Population,
ctr.Name AS Country,
ctr.Region,
ctr.Continent
FROM Country AS ctr
JOIN City AS cty
ON ctr.Code = cty.CountryCode;SELECT Name, Population
FROM City
ORDER BY Population DESC
LIMIT 10 OFFSET 30;