{"id":22367566,"url":"https://github.com/borjamome/madrid_baby_names","last_synced_at":"2025-03-26T15:53:00.849Z","repository":{"id":238692707,"uuid":"797265207","full_name":"BORJAMOME/Madrid_Baby_Names","owner":"BORJAMOME","description":"Analyzing baby names data from the Community of Madrid in 2022","archived":false,"fork":false,"pushed_at":"2024-05-07T14:55:19.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T17:48:07.694Z","etag":null,"topics":["analysis","babynames","madrid","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/BORJAMOME.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}},"created_at":"2024-05-07T14:04:45.000Z","updated_at":"2024-05-17T15:04:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"d0f57a2e-b954-4d0a-b422-2f9c2628f544","html_url":"https://github.com/BORJAMOME/Madrid_Baby_Names","commit_stats":null,"previous_names":["borjamome/madrid_baby_names"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BORJAMOME%2FMadrid_Baby_Names","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BORJAMOME%2FMadrid_Baby_Names/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BORJAMOME%2FMadrid_Baby_Names/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BORJAMOME%2FMadrid_Baby_Names/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BORJAMOME","download_url":"https://codeload.github.com/BORJAMOME/Madrid_Baby_Names/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245689481,"owners_count":20656416,"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":["analysis","babynames","madrid","sql"],"created_at":"2024-12-04T18:19:09.012Z","updated_at":"2025-03-26T15:53:00.839Z","avatar_url":"https://github.com/BORJAMOME.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Analyzing baby names data from the Community of Madrid in 2022\n[![SQL](https://img.shields.io/badge/MySQL-8.0+-f29221?style=for-the-badge\u0026logo=mysql\u0026logoColor=white\u0026labelColor=101010)](https://mysql.com)\n\nThis repository contains SQL queries to analyze a CSV file containing data on baby names born in the Community of Madrid in 2022. The data is sourced from the Instituto de Estadística de la Comunidad de Madrid.\n\n## Files Included\n- **baby_names_madrid_2022.csv**: CSV file containing data on baby names born in the Community of Madrid in 2022.\n- **queries.sql**: SQL queries for analyzing the baby names data.\n\n## SQL Queries Included\n1. **Get the total of unique names per year**: This query calculates the total number of unique names per year.\n```sql\nSELECT year, COUNT(DISTINCT name) AS unique_names\nFROM baby_names\nGROUP BY year;\n```\n![Screenshot 2024-05-07 at 15 44 42](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/6377bbb9-3117-4122-aba3-4faf236f1253)\n\n2. **Calculate the average popularity of names by gender**: This query calculates the average popularity of names by gender.\n ```sql\nSELECT gender, AVG(num) AS avg_popularity\nFROM baby_names\nGROUP BY gender;\n```\n![Screenshot 2024-05-07 at 15 47 25](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/74e8143e-407b-464f-8600-3c554ff62730)\n\n3. **Select first names and the total babies with that name and order by the total number of babies with that name, descending**: This query selects the first names and the total number of babies with each name, ordering them by the total number of babies in descending order.\n```sql\nSELECT name, SUM(num)\n    FROM baby_names\n    GROUP BY name\n    ORDER BY SUM(num) DESC;\n```\n![Screenshot 2024-05-07 at 15 47 51](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/74294122-810d-45be-aba6-9106dfd7cb7f)\n\n4. **Select total babies by gender and order by the total number of babies with that gender, descending**: This query selects the total number of babies by gender and orders them by the total number of babies in descending order.\n```sql\nSELECT gender, SUM(num)\n    FROM baby_names\n    GROUP BY gender\n    ORDER BY SUM(num) DESC;\n```\n![Screenshot 2024-05-07 at 15 48 10](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/4a3589eb-40b8-4326-abc4-fb33ddb5306d)\n\n5. **Classify names by popularity**: This query classifies names by popularity into categories such as 'Very Popular', 'Popular', 'Moderately Popular', 'Not Very Popular', 'Rarely Used', and 'No Data'.\n```sql\nSELECT name, num, \n    CASE WHEN num \u003e 600 then 'Very Popular'\n\t\t WHEN num \u003e 300 then 'Popular'\n         WHEN num \u003e 100 then 'Moderately Popular'\n         WHEN num \u003e 50 then 'Not Very Popular'\n         WHEN num \u003e 1 then 'Rarely Used'\n         else 'No data' end as popularity_type\n\tFROM baby_names;\n```\n![Screenshot 2024-05-07 at 15 49 07](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/961d140a-5425-4a05-bfb4-6f2abbd0b7ef)\n\n6. **Select the top 10 names by gender**: This query selects the top 10 names by gender from the 'baby_names' table, ordering them by their associated number in descending order.\n```sql\nSELECT gender, name, num\nFROM baby_names\nORDER BY num DESC\nLIMIT 10;\n```\n![Screenshot 2024-05-07 at 15 49 26](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/cd2667c0-ff04-4bf8-81da-ccd50d96138f)\n\n7. **Select the top 10 male names**: This query selects the top 10 male from the 'baby_names' table, ordering them by their associated number in descending order.\n```sql\nSELECT name, num\nFROM baby_names\nWHERE gender = 'M'\nORDER BY num DESC\nLIMIT 10;\n```\n![Screenshot 2024-05-07 at 15 49 55](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/f7858a37-be1c-4d3e-92b2-fb2033e96c85)\n\n8. **Select the top 10 female names**: This query selects the top 10 female from the 'baby_names' table, ordering them by their associated number in descending order.\n```sql\nSELECT name, num\nFROM baby_names\nWHERE gender = 'F'\nORDER BY num DESC\nLIMIT 10;\n```\n![Screenshot 2024-05-07 at 15 50 12](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/f39a906f-0902-426c-be78-c2ac94728e38)\n\n9. **Tally the total number of names composed of a single word compared to those composed of two words**: This query calculates the total number of names composed of a single word and those composed of two words.\n```sql\nSELECT \n    SUM(CASE WHEN LENGTH(name) - LENGTH(REPLACE(name, ' ', '')) = 0 THEN 1 ELSE 0 END) AS single_word_names,\n    SUM(CASE WHEN LENGTH(name) - LENGTH(REPLACE(name, ' ', '')) \u003e 0 THEN 1 ELSE 0 END) AS compound_names\nFROM baby_names;\n```\n![Screenshot 2024-05-07 at 15 50 32](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/6522253e-ca92-4241-837e-5f43cf0e56dd)\n\n10. **Select the first letter of each name and count how many names start with that letter**: This query selects the first letter of each name and counts how many names start with that letter.\n```sql\nSELECT \n    SUBSTRING(name, 1, 1) AS first_letter,\n    COUNT(*) AS total_names\nFROM baby_names\nGROUP BY SUBSTRING(name, 1, 1)\nORDER BY first_letter;\n```\n![Screenshot 2024-05-07 at 15 50 53](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/6df7153a-9cba-46e9-99d3-61addc4e023e)\n\n11. **Calculate the probability that a name starts with a certain letter**: This query calculates the probability that a name starts with a certain letter.\n```sql\nSELECT \n    LEFT(name, 1) AS first_letter,\n    COUNT(*) AS name_count,\n    COUNT(*) / (SELECT COUNT(*) FROM baby_names) AS probability\nFROM \n    baby_names\nGROUP BY \n    first_letter\nORDER BY \n    first_letter;\n```\n![Screenshot 2024-05-07 at 15 51 18](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/2920610f-33bf-4507-a6eb-5c9a572bc715)\n\n12. **Select the last letter of each name and count how many names end with that letter**: This query selects the last letter of each name and counts how many names end with that letter.\n```sql\nSELECT \n    RIGHT(name, 1) AS last_letter,\n    COUNT(*) AS name_count\nFROM \n    baby_names\nGROUP BY \n    last_letter\nORDER BY \n    last_letter;\n```\n![Screenshot 2024-05-07 at 15 51 37](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/f37f73d1-8fbb-4b3b-9367-b75a7c6ae965)\n\n13. **Calculate the probability that a name ends with a certain letter**: This query calculates the probability that a name ends with a certain letter.\n```sql\nSELECT \n    last_letter,\n    COUNT(*) AS name_count,\n    COUNT(*) / (SELECT COUNT(*) FROM baby_names) AS probability\nFROM \n    (SELECT RIGHT(name, 1) AS last_letter FROM baby_names) AS last_letters\nGROUP BY \n    last_letter\nORDER BY \n    last_letter;\n```\n![Screenshot 2024-05-07 at 15 52 18](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/fd4e174b-3b9c-4c3f-b3b2-c22c265d7dfe)\n\n14. **Calculate which name has the most letters**: This query calculates which name has the most letters.\n```sql\nSELECT \n    name,\n    LENGTH(name) AS letter_count\nFROM \n    baby_names\nORDER BY \n    letter_count DESC\nLIMIT 1;\n```\n![Screenshot 2024-05-07 at 15 52 40](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/0ccbef25-7292-4af9-8e84-249db5ec4dd9)\n\n15. **Calculate which name has the fewest letters**: This query calculates which name has the fewest letters.\n```sql\nSELECT \n    name,\n    LENGTH(name) AS letter_count\nFROM \n    baby_names\nORDER BY \n    letter_count ASC\nLIMIT 1;\n```\n![Screenshot 2024-05-07 at 15 53 30](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/74b78ff2-0d6d-4661-a91d-b68950043355)\n\n16. **Based on the average number of letters in each name, calculate the probability that a name has X number of letters**: This query calculates the probability that a name has a certain number of letters based on the average number of letters in each name.\n```sql\nSELECT \n    letter_count,\n    COUNT(*) AS name_count,\n    COUNT(*) / (SELECT COUNT(*) FROM baby_names) AS probability\nFROM \n    (SELECT LENGTH(name) AS letter_count FROM baby_names) AS letter_counts\nGROUP BY \n    letter_count\nORDER BY \n    letter_count;\n```\n![Screenshot 2024-05-07 at 15 53 47](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/5d834a16-c934-4f57-81e5-39ab4d2cc505)\n\n17. **What is the probability that being male and born in 2022, I have one name or another?**: This query calculates the probability that being male and born in 2022, one has one name or another.\n```sql\nSELECT \n    name,\n    SUM(num) AS total_name_count,\n    CONCAT(FORMAT((SUM(num) / (SELECT SUM(num) FROM baby_names WHERE gender = 'M')) * 100, 2), '%') AS probability\nFROM \n    baby_names\nWHERE \n    gender = 'M'\nGROUP BY \n    name;\n```\n![Screenshot 2024-05-07 at 15 54 08](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/45e2f156-e812-4930-b216-39e820e9d5b4)\n\n18. **What is the probability that being female and born in 2022, I have one name or another?**: This query calculates the probability that being female and born in 2022, one has one name or another.\n```sql\nSELECT \n    name,\n    SUM(num) AS total_name_count,\n    CONCAT(FORMAT((SUM(num) / (SELECT SUM(num) FROM baby_names WHERE gender = 'M')) * 100, 2), '%') AS probability\nFROM \n    baby_names\nWHERE \n    gender = 'F'\nGROUP BY \n    name;\n```\n![Screenshot 2024-05-07 at 15 54 37](https://github.com/BORJAMOME/Madrid_Baby_Names/assets/19588053/8ed218cc-1098-4ca0-93fe-2cd5165080ba)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborjamome%2Fmadrid_baby_names","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fborjamome%2Fmadrid_baby_names","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborjamome%2Fmadrid_baby_names/lists"}