{"id":27651888,"url":"https://github.com/tunjis/world-database-analysis_sql","last_synced_at":"2025-07-08T03:35:03.437Z","repository":{"id":289253863,"uuid":"970590950","full_name":"tunjis/World-Database-Analysis_SQL","owner":"tunjis","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-22T12:48:24.000Z","size":89,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-24T04:59:49.458Z","etag":null,"topics":["data-analysis","mysql","sql"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tunjis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-22T08:38:22.000Z","updated_at":"2025-04-23T12:11:28.000Z","dependencies_parsed_at":"2025-04-22T11:23:14.459Z","dependency_job_id":"833a021b-5c45-4ffa-bda5-5f877dae2724","html_url":"https://github.com/tunjis/World-Database-Analysis_SQL","commit_stats":null,"previous_names":["tunjis/sql"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tunjis%2FWorld-Database-Analysis_SQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tunjis%2FWorld-Database-Analysis_SQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tunjis%2FWorld-Database-Analysis_SQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tunjis%2FWorld-Database-Analysis_SQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tunjis","download_url":"https://codeload.github.com/tunjis/World-Database-Analysis_SQL/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250566452,"owners_count":21451230,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-analysis","mysql","sql"],"created_at":"2025-04-24T05:00:03.369Z","updated_at":"2025-04-24T05:00:04.176Z","avatar_url":"https://github.com/tunjis.png","language":null,"funding_links":["https://www.buymeacoffee.com/jstunjisu"],"categories":[],"sub_categories":[],"readme":"# 📊 World-Database-Analysis \u003ca href=\"https://www.mysql.com/\" target=\"_blank\" rel=\"noreferrer\"\u003e\u003cimg src=\"https://cdn.jsdelivr.net/gh/devicons/devicon/icons/mysql/mysql-original.svg\" width=\"36\" height=\"36\" alt=\"MySQL\"/\u003e **MySQL** \u003c/a\u003e\u0026nbsp;\n\n\u003ca href=\"https://www.mysql.com/\" target=\"_blank\" rel=\"noreferrer\"\u003e\u003cimg src=\"https://cdn.jsdelivr.net/gh/devicons/devicon/icons/mysql/mysql-original.svg\" width=\"36\" height=\"36\" alt=\"MySQL\"/\u003e \u003c/a\u003e\u0026nbsp; [word db(1).sql](https://justit831-my.sharepoint.com/:u:/g/personal/justincracium_bootcamp_justit_co_uk/EYFUDcPxgehEhuULTiBi8-EBkN6T5jyUOKS7JTGi18Ei1w?e=xqeYqF)\n\n\n**Objective:** To demonstrate proficiency in SQL by querying the `world` database to answer a variety of analytical questions, showcasing skills in data retrieval, filtering, aggregation, and joining techniques.\n\n**Key Activities \u0026 Skills Demonstrated:**\n\n* **Database Setup:** Utilised the standard `world` database schema containing information about countries, cities, and languages.\n* **Data Retrieval (`SELECT`):** Extracted specific columns and all columns (`*`) from tables. Used `AS` to create meaningful aliases for columns.\n* **Filtering (`WHERE`):** Applied various conditions using operators like `=`, `\u003e`, `BETWEEN`, `LIKE` (with `%` wildcard), and `IS NOT NULL` to isolate specific data subsets.\n* **Sorting (`ORDER BY`):** Arranged results in ascending (`ASC`) and descending (`DESC`) order based on column values.\n* **Limiting Results (`LIMIT`):** Restricted the number of rows returned, including using offsets to fetch specific ranges.\n* **Aggregation (`GROUP BY`, Aggregate Functions):** Grouped data using `GROUP BY` and performed calculations using functions like `COUNT()` and `AVG()`. Applied `ROUND()` for cleaner numerical output.\n* **Joining Tables (`JOIN`):** Combined data from multiple tables (`city`, `country`) based on related columns (e.g., `CountryCode`, `Capital ID`) using `JOIN` clauses (implicitly INNER JOIN).\n* **Calculations:** Performed arithmetic calculations within queries (e.g., Population Density, GNP per Capita).\n* **Subqueries:** Used subqueries for complex filtering conditions (e.g., finding cities in countries with above-average GNP per capita).\n\n---\n\n**Schema for the 'word' database** \u003cimg src=\"schema.png\" width=\"1000\" height=\"700\"/\u003e \n\n---\n\n## 💡 SQL Query Examples \u0026 Scenarios\n\nHere are the specific SQL queries used to address the analytical tasks based on the `world` database:\n\n1.  **Count Cities in USA:** Determine the total number of cities within the United States.\n    ```sql\n    SELECT COUNT(*) AS TotalUSACities\n    FROM city\n    WHERE CountryCode = 'USA';\n    ```\n\n2.  **Country with Highest Life Expectancy:** Identify the country with the highest life expectancy.\n    ```sql\n    SELECT Name, LifeExpectancy\n    FROM country\n    WHERE LifeExpectancy IS NOT NULL\n    ORDER BY LifeExpectancy DESC\n    LIMIT 1;\n    ```\n\n3.  **Cities Containing 'New':** Compile a list of world cities whose names include 'New'.\n    ```sql\n    SELECT Name, CountryCode\n    FROM city\n    WHERE Name LIKE '%New%'\n    ORDER BY Name;\n    ```\n\n4.  **Top 10 Most Populous Cities:** List the first 10 cities by population globally.\n    ```sql\n    SELECT Name, CountryCode, Population\n    FROM city\n    ORDER BY Population DESC\n    LIMIT 10;\n    ```\n\n5.  **Cities with Population \u003e 2 Million:** Identify cities with populations exceeding 2 million.\n    ```sql\n    SELECT Name, CountryCode, Population\n    FROM city\n    WHERE Population \u003e 2000000\n    ORDER BY Population DESC;\n    ```\n\n6.  **Cities Starting with 'Be':** Compile a list of cities starting with the prefix 'Be'.\n    ```sql\n    SELECT Name, CountryCode\n    FROM city\n    WHERE Name LIKE 'Be%'\n    ORDER BY Name;\n    ```\n\n7.  **Mid-Sized Cities (Population 500k-1M):** Identify cities with populations between 500,000 and 1 million.\n    ```sql\n    SELECT Name, CountryCode, Population\n    FROM city\n    WHERE Population BETWEEN 500000 AND 1000000\n    ORDER BY Population DESC;\n    ```\n\n8.  **Cities Sorted Alphabetically:** Provide a list of all cities sorted by name (A-Z).\n    ```sql\n    SELECT Name, CountryCode\n    FROM city\n    ORDER BY Name ASC;\n    ```\n\n9.  **Most Populated City:** Identify the single most populated city in the database.\n    ```sql\n    SELECT Name, CountryCode, Population\n    FROM city\n    ORDER BY Population DESC\n    LIMIT 1;\n    ```\n\n10. **City Name Frequency Analysis:** List unique city names alphabetically with their counts.\n    ```sql\n    SELECT Name, COUNT(*) AS Frequency\n    FROM city\n    GROUP BY Name\n    ORDER BY Name ASC;\n    ```\n\n11. **City with Lowest Population:** Identify the city with the smallest population.\n    ```sql\n    SELECT Name, CountryCode, Population\n    FROM city\n    ORDER BY Population ASC\n    LIMIT 1;\n    ```\n\n12. **Country with Largest Population:** Identify the country with the highest population.\n    ```sql\n    SELECT Name, Population\n    FROM country\n    ORDER BY Population DESC\n    LIMIT 1;\n    ```\n\n13. **Capital of Spain:** Identify the capital city of Spain.\n    ```sql\n    SELECT city.Name AS CapitalCity\n    FROM country\n    JOIN city ON country.Capital = city.ID\n    WHERE country.Code = 'ESP';\n    ```\n\n14. **Cities in Europe:** Compile a list of cities located on the continent of Europe.\n    ```sql\n    SELECT city.Name AS CityName, country.Name AS CountryName\n    FROM city\n    JOIN country ON city.CountryCode = country.Code\n    WHERE country.Continent = 'Europe'\n    ORDER BY city.Name ASC;\n    ```\n\n15. **Average City Population by Country:** Calculate the average city population for each country.\n    ```sql\n    SELECT\n        country.Name AS CountryName,\n        ROUND(AVG(city.Population), 0) AS AverageCityPopulation -- Calculate and round average\n    FROM\n        city\n    JOIN  -- INNER JOIN is default\n        country ON city.CountryCode = country.Code\n    GROUP BY\n        country.Code, country.Name -- Group results per country\n    ORDER BY\n        country.Name ASC; -- Sort alphabetically\n    ```\n\n16. **Capital Cities Population Comparison:** List capital cities worldwide, ordered by population.\n    ```sql\n    SELECT\n        city.Name AS CapitalCity,\n        country.Name AS CountryName,\n        city.Population AS CapitalPopulation\n    FROM\n        city\n    JOIN\n        country ON city.ID = country.Capital -- Link city to country using the Capital ID\n    ORDER BY\n        city.Population DESC; -- Order by the capital's population\n    ```\n\n17. **Countries with Low Population Density:** Identify the 25 countries with the lowest population density (people per square km).\n    ```sql\n    SELECT\n        Name,\n        Population,\n        SurfaceArea,\n        ROUND((Population / SurfaceArea), 2) AS PopulationDensity_PerSqKm -- Calculate and round density\n    FROM\n        country\n    WHERE\n        SurfaceArea \u003e 0 AND Population \u003e 0 -- Exclude uninhabited areas or those with zero area\n    ORDER BY\n        PopulationDensity_PerSqKm ASC -- Order by density, lowest first\n    LIMIT 25; -- Show the 25 least dense\n    ```\n\n18. **Cities with High GNP per Capita (Country Level):** Identify cities located in countries with an above-average Gross National Product (GNP) per capita.\n    ```sql\n    SELECT\n        city.Name AS CityName,\n        country.Name AS CountryName,\n        ROUND((country.GNP / country.Population), 2) AS CountryGNP_PerCapita -- Show country's figure\n    FROM\n        city\n    JOIN\n        country ON city.CountryCode = country.Code\n    WHERE\n        country.Population \u003e 0 AND country.GNP \u003e 0 -- Ensure valid data for calculation\n        AND (country.GNP / country.Population) \u003e (\n             -- Subquery calculates the overall average country GNP per capita\n            SELECT AVG(GNP / Population)\n            FROM country\n            WHERE Population \u003e 0 AND GNP \u003e 0 AND GNP IS NOT NULL\n        )\n    ORDER BY\n        CountryGNP_PerCapita DESC, -- Show cities in highest GNP-per-capita countries first\n        country.Name ASC,\n        city.Name ASC;\n    ```\n\n19. **Cities Ranked 31-40 by Population:** List cities ranked 31st to 40th by population.\n    ```sql\n    SELECT Name, CountryCode, Population\n    FROM city\n    ORDER BY Population DESC\n    LIMIT 30, 10; -- Skip 30 rows, take the next 10\n    ```\n\n---\n\n### Summary of Key SQL Skills Demonstrated:\n\n* **Data Querying:** `SELECT`, `FROM`, `WHERE`.\n* **Filtering:** Comparison operators (`=`, `\u003e`, `BETWEEN`), `LIKE`, `IS NOT NULL`.\n* **Sorting \u0026 Limiting:** `ORDER BY` (`ASC`, `DESC`), `LIMIT` (including offset).\n* **Aggregation:** `GROUP BY`, `COUNT()`, `AVG()`.\n* **Joining:** `JOIN ... ON` (primarily INNER joins demonstrated).\n* **Data Manipulation:** Aliasing (`AS`), basic arithmetic, `ROUND()`.\n* **Subqueries:** Used for filtering based on aggregated results.\n\n---\n\n### 🧑‍💻 Created by [tunjis](https://github.com/tunjis) \n\n \n\n* 🌍  Based in \u003ca href=\"https://maps.app.goo.gl/hMxhRX5ptQAAkL7NA/\" target=\"_blank\"\u003e**London**\u003c/a\u003e\n* 🖥️  See my portfolio at [Data’s the new oil. I’m the refinery.](https://github.com/tunjis?tab=repositories)\n* 📫  Contact me via my [LinkedIn profile](https://linkedin.com/in/justincraciun/)\n* 🧠  Learning Data Science\n* 🤝  Open to collaborating on interesting projects\n* ⚡  AI enthusiast\n\n---\n\n### 🛠️ Technical Skills\n\u003ca href=\"https://www.python.org/\" target=\"_blank\" rel=\"noreferrer\"\u003e\u003cimg src=\"https://cdn.jsdelivr.net/gh/devicons/devicon/icons/python/python-original.svg\" width=\"36\" height=\"36\" alt=\"Python\"/\u003e **Python** \u003c/a\u003e\u0026nbsp;\n\u003ca href=\"https://www.microsoft.com/en-us/microsoft-365/excel\" target=\"_blank\" rel=\"noreferrer\"\u003e\u003cimg src=\"https://img.icons8.com/color/24/000000/microsoft-excel-2019--v1.png\" width=\"36\" height=\"36\" alt=\"Microsoft Excel\"/\u003e **Microsoft Excel** \u003c/a\u003e\u0026nbsp;\n\u003ca href=\"https://www.mysql.com/\" target=\"_blank\" rel=\"noreferrer\"\u003e\u003cimg src=\"https://cdn.jsdelivr.net/gh/devicons/devicon/icons/mysql/mysql-original.svg\" width=\"36\" height=\"36\" alt=\"MySQL\"/\u003e **MySQL** \u003c/a\u003e\u0026nbsp;\n\u003ca href=\"https://www.tableau.com/\" target=\"_blank\" rel=\"noreferrer\"\u003e\u003cimg src=\"https://img.icons8.com/color/24/000000/tableau-software.png\" width=\"36\" height=\"36\" alt=\"Tableau\"/\u003e **Tableau** \u003c/a\u003e\u0026nbsp;\n\u003ca href=\"https://powerbi.microsoft.com/\" target=\"_blank\" rel=\"noreferrer\"\u003e\u003cimg src=\"https://img.icons8.com/color/24/000000/power-bi.png\" width=\"36\" height=\"36\" alt=\"Power BI\"/\u003e **Power BI** \u003c/a\u003e\u0026nbsp;  \n\n\u003ca href=\"https://azure.microsoft.com/\" target=\"_blank\" rel=\"noreferrer\"\u003e\u003cimg src=\"https://cdn.jsdelivr.net/gh/devicons/devicon/icons/azure/azure-original.svg\" width=\"36\" height=\"36\" alt=\"Microsoft Azure\"/\u003e **Microsoft Azure** \u003c/a\u003e\u0026nbsp;\n\u003ca href=\"https://cloud.google.com/\" target=\"_blank\" rel=\"noreferrer\"\u003e\u003cimg src=\"https://cdn.jsdelivr.net/gh/devicons/devicon/icons/googlecloud/googlecloud-original.svg\" width=\"36\" height=\"36\" alt=\"Google Cloud\"/\u003e **Google Cloud** \u003c/a\u003e\u0026nbsp;\n\u003ca href=\"https://colab.research.google.com/\" target=\"_blank\" rel=\"noreferrer\"\u003e\u003cimg src=\"https://img.icons8.com/color/48/000000/google-colab.png\" width=\"36\" height=\"36\" alt=\"Google Colab\"/\u003e **Google Colab** \u003c/a\u003e\u0026nbsp;\u0026nbsp;  \n\n---\n\n### 🔁 Socials\n\n\u003ca href=\"https://www.github.com/tunjis/\" target=\"_blank\" rel=\"noreferrer\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://raw.githubusercontent.com/danielcranney/readme-generator/main/public/icons/socials/github-dark.svg\" /\u003e\n    \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://raw.githubusercontent.com/danielcranney/readme-generator/main/public/icons/socials/github.svg\" /\u003e\n    \u003cimg alt=\"GitHub Profile\" src=\"https://raw.githubusercontent.com/danielcranney/readme-generator/main/public/icons/socials/github.svg\" width=\"32\" height=\"32\" /\u003e\n  \u003c/picture\u003e\n\u003c/a\u003e\u0026nbsp;\n\u003ca href=\"https://linkedin.com/in/justincraciun/\" target=\"_blank\" rel=\"noreferrer\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://raw.githubusercontent.com/danielcranney/readme-generator/main/public/icons/socials/linkedin-dark.svg\" /\u003e\n    \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://raw.githubusercontent.com/danielcranney/readme-generator/main/public/icons/socials/linkedin.svg\" /\u003e\n    \u003cimg alt=\"LinkedIn Profile\" src=\"https://raw.githubusercontent.com/danielcranney/readme-generator/main/public/icons/socials/linkedin.svg\" width=\"32\" height=\"32\" /\u003e\n  \u003c/picture\u003e\n\u003c/a\u003e\u0026nbsp;\u0026nbsp;  \n\n---\n\n### ☕ Support Me\n\n\u003ca href=\"https://www.buymeacoffee.com/jstunjisu\" target=\"_blank\" rel=\"noreferrer\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" width=\"150\" alt=\"Buy Me A Coffee\"/\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftunjis%2Fworld-database-analysis_sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftunjis%2Fworld-database-analysis_sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftunjis%2Fworld-database-analysis_sql/lists"}