{"id":20021750,"url":"https://github.com/ndleah/health-analysis","last_synced_at":"2025-03-02T03:43:03.821Z","repository":{"id":105089102,"uuid":"370952671","full_name":"ndleah/health-analysis","owner":"ndleah","description":"This case study is contained within the Serious SQL course by Danny Ma","archived":false,"fork":false,"pushed_at":"2021-09-14T18:42:31.000Z","size":1096,"stargazers_count":15,"open_issues_count":0,"forks_count":10,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-12T16:30:58.815Z","etag":null,"topics":["data-analysis","data-exploration","data-with-danny","database","serious-sql","sql"],"latest_commit_sha":null,"homepage":"https://www.datawithdanny.com/","language":"SQL","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/ndleah.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}},"created_at":"2021-05-26T07:56:43.000Z","updated_at":"2023-12-14T00:15:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"bffbbef7-01d7-4400-b20c-b3f815ee0151","html_url":"https://github.com/ndleah/health-analysis","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndleah%2Fhealth-analysis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndleah%2Fhealth-analysis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndleah%2Fhealth-analysis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndleah%2Fhealth-analysis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ndleah","download_url":"https://codeload.github.com/ndleah/health-analysis/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241455380,"owners_count":19965602,"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","data-exploration","data-with-danny","database","serious-sql","sql"],"created_at":"2024-11-13T08:38:06.341Z","updated_at":"2025-03-02T03:43:03.802Z","avatar_url":"https://github.com/ndleah.png","language":"SQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Star Badge](https://img.shields.io/static/v1?label=%F0%9F%8C%9F\u0026message=If%20Useful\u0026style=style=flat\u0026color=BC4E99)\n![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)\n[![View My Profile](https://img.shields.io/badge/View-My_Profile-green?logo=GitHub)](https://github.com/ndleah)\n[![View Repositories](https://img.shields.io/badge/View-My_Repositories-blue?logo=GitHub)](https://github.com/ndleah?tab=repositories)\n\n# Health Analytics Case Study \u003cimg src=\"/IMG/pngwing.com.png\" align=\"right\" width=\"120\" /\u003e\n\n\u003e This case study is contained within the [Serious SQL](https://www.datawithdanny.com) by [Danny Ma](https://www.linkedin.com/in/datawithdanny/)\n\u003e \n## 📕 **Table of contents**\n\u003c!--ts--\u003e\n   * 🛠️ [Overview](#️-overview)\n   * 🚀 [Solutions](#-solutions)\n   * 💻 [Key Highlights](#-key-highlight)\n\n\n## 🛠️ Overview\nWith the **Health Analytics Mini Case Study**, I queried data to bring insights to the following questions:\n1. How many `unique users` exist in the logs dataset?\n2. How many total `measurements` do we have `per user on average`?\n3. What about the `median` number of measurements per user?\n4. How many users have `3 or more` measurements?\n5. How many users have `1,000 or more` measurements?\n6. Have logged `blood glucose` measurements?\n7. Have `at least 2 types` of measurements?\n8. Have all 3 measures - `blood glucose, weight and blood pressure`?\n9. What is the `median systolic/diastolic` **blood pressure** values?\n\n---\n## 🚀 Solutions\n\n![Question 1](https://img.shields.io/badge/Question-1-971901)\n### **How many unique users exist in the logs dataset?**\n```sql\nSELECT COUNT (DISTINCT id)\nFROM health.user_logs;\n```\n\n|count                                   |\n|----------------------------------------|\n|554                                     |\n\n\n\n**`Note:` For question 2-8, I created a temporary table:**\n\n**Step 1:** Firstly, I ran a code `DROP TABLE IF EXISTS` statement to clear out any previously created tables:\n  ```sql\n  DROP TABLE IF EXISTS user_measure_count;\n  ```\n**Step 2:** Next, I created a new **temporary table** using the results of the query below:\n  ```sql\n  CREATE TEMP TABLE user_measure_count AS\n  SELECT \n    id,\n    COUNT(*) AS measure_count,\n    COUNT (DISTINCT measure) AS unique_measures\n  FROM health.user_logs\n  GROUP BY 1;\n  ```\n\n![Question 2](https://img.shields.io/badge/Question-2-971901)\n### **How many total measurements do we have per user on average?**\n```sql\nSELECT\n  ROUND (AVG(measure_count), 2) AS mean_value\nFROM user_measure_count;\n```\n\n|mean_value                              |\n|----------------------------------------|\n|79.23                                   |\n\n---\n\n![Question 3](https://img.shields.io/badge/Question-3-971901)\n### **What about the median number of measurements per user?**\n```sql \nSELECT \n   PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY measure_count) AS median_value \nFROM user_measure_count;\n```\n\n|median_value                            |\n|----------------------------------------|\n|2                                       |\n\n\n\n![Question 4](https://img.shields.io/badge/Question-4-971901)\n### **How many users have 3 or more measurements?**\n```sql\nSELECT COUNT(*)\nFROM user_measure_count\nWHERE measure_count \u003e= 3;\n```\n\n|count                                   |\n|----------------------------------------|\n|209                                     |\n\n\n![Question 5](https://img.shields.io/badge/Question-5-971901)\n### **How many users have 1,000 or more measurements?**\n```sql \nSELECT COUNT(*)\nFROM user_measure_count\nWHERE measure_count \u003e= 1000;\n```\n\n|count                                   |\n|----------------------------------------|\n|5                                       |\n\n---\n\n![Question 6](https://img.shields.io/badge/Question-6-971901)\n### **Have logged blood glucose measurements?**\n```sql\nSELECT \n  COUNT(DISTINCT id)\nFROM health.user_logs\nWHERE measure = 'blood_glucose';\n```\n\n|count                                   |\n|----------------------------------------|\n|325                                     |\n\n---\n\n![Question 7](https://img.shields.io/badge/Question-7-971901)\n### 7. **Have at least 2 types of measurements?**\n```sql\nSELECT \n  COUNT(*)\nFROM user_measure_count\nWHERE unique_measures \u003e= 2;\n```\n\n\n|count                                   |\n|----------------------------------------|\n|204                                     |\n\n---\n\n![Question 8](https://img.shields.io/badge/Question-8-971901)\n### **Have all 3 measures - blood glucose, weight and blood pressure?**\n```sql\nSELECT\n  COUNT(*)\nFROM user_measure_count\nWHERE unique_measures = 3;\n```\n\n|count                                   |\n|----------------------------------------|\n|50                                      |\n\n---\n\n![Question 9](https://img.shields.io/badge/Question-9-971901)\n### **What is the median systolic/diastolic blood pressure values?**\n```sql\nSELECT\n  PERCENTILE_CONT(0.5) WITHIN GROUP(ORDER BY systolic) AS median_systolic,\n  PERCENTILE_CONT(0.5) WITHIN GROUP(ORDER BY diastolic) AS median_diastolic\nFROM health.user_logs\nWHERE measure = 'blood_pressure';\n```\n\n|median_systolic|median_diastolic|\n|---------------|----------------|\n|126            |79              |\n---\n## 💻 Key Highlight\n\u003e **Initial thoughts:** \nEven though this is a short assignment which cover basic SQL syntax, I did run into problems several time during the solving process. However, it helped me to have a better understanding about data exploration using SQL from theories to real life application.\n\nSome of the main areas covered in this case study, including:\n* **Sorting Values**\n* **Inspect Row Counts** \n* **Duplicates \u0026 Record Frequency Review**\n* **Summary Statistics** `(MEAN, MEDIAN)`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndleah%2Fhealth-analysis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fndleah%2Fhealth-analysis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndleah%2Fhealth-analysis/lists"}