{"id":15002914,"url":"https://github.com/glitzzybetty/sql-personal-project","last_synced_at":"2026-03-11T19:01:50.025Z","repository":{"id":244763713,"uuid":"816192270","full_name":"Glitzzybetty/SQL-Personal-Project","owner":"Glitzzybetty","description":"This is a show case of my SQL super powers in an assumed fictional company","archived":false,"fork":false,"pushed_at":"2024-07-11T00:21:57.000Z","size":270,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-18T13:56:22.366Z","etag":null,"topics":["business-analytics","business-intelligence","dataanalytics","database","mssql-database","sql"],"latest_commit_sha":null,"homepage":"https://glitzzybetty.github.io/SQL-Project/","language":"TSQL","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/Glitzzybetty.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-06-17T08:20:56.000Z","updated_at":"2024-07-11T00:22:01.000Z","dependencies_parsed_at":"2024-06-17T09:54:32.568Z","dependency_job_id":"6c431933-bddf-4a95-b6b1-273ae9ca961a","html_url":"https://github.com/Glitzzybetty/SQL-Personal-Project","commit_stats":null,"previous_names":["glitzzybetty/sql-project"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glitzzybetty%2FSQL-Personal-Project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glitzzybetty%2FSQL-Personal-Project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glitzzybetty%2FSQL-Personal-Project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glitzzybetty%2FSQL-Personal-Project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Glitzzybetty","download_url":"https://codeload.github.com/Glitzzybetty/SQL-Personal-Project/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243153603,"owners_count":20244791,"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":["business-analytics","business-intelligence","dataanalytics","database","mssql-database","sql"],"created_at":"2024-09-24T18:53:57.442Z","updated_at":"2026-03-11T19:01:44.970Z","avatar_url":"https://github.com/Glitzzybetty.png","language":"TSQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1\u003eCase Study #1 - Analyze Data in a Model Car Database \u003c/h1\u003e\n\u003cimg width=\"1000\" alt=\"dashboard\" src=\"https://github.com/Glitzzybetty/SQL-Personal-Project/assets/130115684/0ad017d9-ec71-4764-bddb-81eea66fd59f\"\u003e\n\n\u003ch1\u003eContents\u003c/h1\u003e\n\u003cul\u003e\n  \u003cli\u003e\u003ca href=\"#introduction\"\u003eIntroduction\u003c/a\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ca href=\"#problemstatement\"\u003eProject Scenerio\u003c/a\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ca href=\"#objective\"\u003eProject Objective\u003c/a\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ca href=\"#database\"\u003eDatabase Information\u003c/a\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ca href=\"#casestudyquestionsandsolutions\"\u003eCase Study Questions \u0026 Solutions\u003c/a\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ca href=\"#bonusquestionsandsolutions\"\u003eBonus Questions \u0026 Solutions\u003c/a\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ca href=\"#keyinsights\"\u003eKey Insights\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003ch2\u003e\u003ca name=\"Introduction\"\u003eIntroduction\u003c/a\u003e\u003c/h1\u003e\n\u003cp\u003eAs a data analyst at the fictional Mint Classics Company, am helping to analyze data in a relational database with the goal of supporting inventory-related business decisions that lead to the closure of a storage facility.\u003c/p\u003e\n\n\u003ch2\u003e\u003ca name=\"problemstatement\"\u003eProject Scenerio\u003c/a\u003e\u003c/h1\u003e\n\u003cp\u003e Mint Classics Company, a retailer of classic model cars and other vehicles, is looking at closing one of their storage facilities. \nTo support a data-based business decision, they are looking for suggestions and recommendations for reorganizing or reducing inventory, while still maintaining timely service to their customers. For example, they would like to be able to ship a product to a customer within 24 hours of the order being placed.\u003c/p\u003e\n\n\u003ch2\u003e\u003ca name=\"objective\"\u003eProject Objective\u003c/a\u003e\u003c/h1\u003e\n\u003cp\u003e\n\u003cul\u003e1. Explore products currently in inventory.\u003c/ul\u003e\n\u003cul\u003e2. Determine important factors that may influence inventory reorganization/reduction.\u003c/ul\u003e\n\u003cul\u003e3. Provide analytic insights and data-driven recommendations.\u003c/ul\u003e\n\u003c/p\u003e\n\n\u003ch2\u003e\u003ca name=\"database\"\u003eDatabase Information\u003c/a\u003e\u003c/h1\u003e\n\u003cp\u003eThe Database for this project was initially configured to MySQL pattern, I had to convert it to MSSQL pattern. Re-wrote the table creations, and the data insertions with the order datails containing more that 1000 rows. I used partly AI prompting as additional assistance for ideas. It was QED.\u003c/p\u003e\nMint Classic Entity Relationship Diagram (ERD)\n\u003cimg width=\"500\" alt='MintDB ERD' src= \"https://github.com/Glitzzybetty/SQL-Project/assets/130115684/9ca464ac-982a-4d77-80a4-c1077fce2570\"\u003e\n\n\u003ch1\u003e\u003ca name=\"casestudyquestionsandsolutions\"\u003eExploring to understand some Business Demographic Information\u003c/a\u003e\u003c/h1\u003e\n\u003cp\u003eIt is very important to find out out business demography, customer segments, doing some background checks before attemping to fix underlying problems.\u003c/p\u003e\n\u003col\u003e\n\n  \u003cli\u003e\u003ch5\u003eWhere are the top five customers aggregations located\u003c/h5\u003e\u003c/li\u003e\n\t\n```sql\n-- Top 5 Countries of Mint Classic customers\nselect top 5\ncountry, \ncount(customerNumber) as [Number of Customers],\nround(avg(creditLimit),0) as [Average Credit Limit]\nfrom [mintclassics].[dbo].[customers]\ngroup by country \norder by count(customerNumber) desc\n```\n\u003ch6\u003eAnswer:\u003c/h6\u003e\n\u003cimg width=\"500\" alt=\"Top 5 customers information\" src=\"https://github.com/Glitzzybetty/SQL-Project/assets/130115684/5bb358a7-bae7-4cc0-9e61-bd9c633ce4ce\"\u003e\n\u003cul\u003e\n  \u003cli\u003eThe SQL query retrieves the \u003ccode\u003ecustomerNumber\u003c/code\u003e shows their \u003ccode\u003ecountry\u003c/code\u003e of residents and calculates the average (\u003ccode\u003ecreditLimit\u003c/code\u003e) in each country group they belong to.\u003c/li\u003e\n  \u003cli\u003eIt presents data from the \u003ccode\u003ecustomers\u003c/code\u003e table.\n  \u003cli\u003eThe results are grouped by top 5 \u003ccode\u003ecountry\u003c/code\u003e.\u003c/li\u003e\n  \u003cli\u003eThe query then calculates the average \u003ccode\u003ecreditlimit\u003c/code\u003e for each group of customers with the same \u003ccode\u003ecountry\u003c/code\u003e.\u003c/li\u003e\n  \u003cli\u003eFinally, the results are sorted in descending order based on the \u003ccode\u003ecustomerNumber\u003c/code\u003e aggregation.\u003c/li\u003e\n\t\u003cli\u003eThe findings here shows that there are more customers in the USA\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003cli\u003e\u003ch5\u003eExplain MintClassic Employees hierarchy, and their aggregation per location \u003c/h5\u003e\u003c/li\u003e\n\t\n```sql\nSELECT \n    e1.jobTitle,\n    COUNT(e1.employeeNumber) AS EmployeeCount,\n    COALESCE(\n        CONCAT(e2.firstName, ' ', e2.lastName),\n        'No one' -- This will show 'No one' for the President\n    ) AS [Report to Person],\n\n\tCOALESCE(\n        e2.jobTitle,\n        'No one' -- This will show 'No one' for the President\n    ) AS [Report To Person Job Title],\n\tCOALESCE(\n        o.[country],\n        'No one' -- This will show 'No one' for the President\n    ) AS [Report To Person Country]\nFROM \n    [mintclassics].[dbo].[employees] e1\nLEFT JOIN \n    [mintclassics].[dbo].[employees] e2 ON e1.reportsTo = e2.employeeNumber\nJOIN \n    [mintclassics].[dbo].[offices] o ON  e2.officeCode = o.officeCode\nGROUP BY \n    e1.jobTitle,\n\te2.jobTitle,\n    e2.firstName, \n    e2.lastName,\n\t o.[country]\nORDER BY \n    EmployeeCount DESC;\n```\n\u003ch6\u003eAnswer:\u003c/h6\u003e\n\u003cimg width=\"500\" alt=\"Employee Hierarchy and aggregation per location\" src=\"https://github.com/Glitzzybetty/SQL-Project/assets/130115684/1b7f75cb-bee4-4620-9b29-d5493c971f55\"\u003e\n\u003cul\u003e\n  \u003cli\u003eThe SQL query retrieves the \u003ccode\u003eJobTitle\u003c/code\u003e of Employees, shows the count of\u003ccode\u003eEmployeeNumber\u003c/code\u003e in that position and the report to person, their jobtitle and their \u003ccode\u003ecountry\u003c/code\u003e.\u003c/li\u003e\n  \u003cli\u003eIt presents data from the \u003ccode\u003eEmployees\u003c/code\u003e table, self joins to get report to person and joins with \u003ccode\u003eofficecode\u003c/code\u003e to get the \u003ccode\u003ecountry\u003c/code\u003e i.e. location of these staffs.\n  \u003cli\u003eThe results are grouped by top 5 \u003ccode\u003ejobTitle\u003c/code\u003e \u003ccode\u003enames\u003c/code\u003e and \u003ccode\u003ecountry\u003c/code\u003e.\u003c/li\u003e\n  \u003cli\u003eThe findings points out that majority of employees were from USA, pointing out the reasons more customers are the largest in US. Also, it was discovered one employee who is a sales rep reports to another sales rep in Japan, some questions needs to be asked the stakeholders, especially the VP sales.\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/ol\u003e\n\u003ch1\u003e\u003ca name=\"casestudyquestionsandsolutions\"\u003eAdvance Questions\u003c/a\u003e\u003c/h1\u003e\n\u003cp\u003eCritical Question are being asked to reveal Business problems, so that solution can be readily presented\u003c/p\u003e\n\u003col\u003e\n  \u003cli\u003e\u003ch5\u003e Are there products with high inventory but low sales? How can we optimize the inventory of these products? \u003c/h5\u003e\u003c/li\u003e\n\t\n```sql\nWITH product_sales AS (\n    SELECT \n        p.productCode, \n        p.productName, \n        p.quantityInStock,\n        ISNULL(SUM(od.quantityOrdered), 0) AS totalQuantitySold,\n        ISNULL(SUM(od.quantityOrdered * od.priceEach) / NULLIF(AVG(p.quantityInStock), 0), 1) AS InventoryTurnOverRatio,\n        ISNULL(AVG(p.quantityInStock) / NULLIF(SUM(od.quantityOrdered * od.priceEach), 0), 1) AS StockToSalesRatio\n    FROM \n        products p\n    LEFT JOIN \n        orderdetails od ON p.productCode = od.productCode\n    GROUP BY \n        p.productCode, p.productName, p.quantityInStock, p.MSRP\n)\nSELECT TOP 10\n    productCode, \n    productName, \n    quantityInStock, \n    totalQuantitySold,\n    InventoryTurnOverRatio, \n    CAST(ROUND(StockToSalesRatio, 2) AS float) AS StockToSalesRatio\nFROM \n    product_sales\nORDER BY \n    StockToSalesRatio DESC;\n```\n\u003ch6\u003eAnswer 1:\u003c/h6\u003e\n\u003cimg width=\"500\" alt=\"Inventory vs Order\" src=\"https://github.com/Glitzzybetty/SQL-Project/assets/130115684/8762c528-af8e-4efd-939a-20c12a740134\"\u003e\n\u003cul\u003e\n\u003cli\u003eThe SQL uses \u003ch4\u003e CTE i.e. common Table Expression(product_sales):\u003c/h4\u003e\u003c/li\u003e\n\u003cli\u003eCalculates \u003ccode\u003etotalQuantitySold\u003c/code\u003e, \u003ccode\u003eInventoryTurnOverRatio\u003c/code\u003e, and \u003ccode\u003eStockToSalesRatio\u003c/code\u003e.\u003c/li\u003e\n\u003cli\u003eUses ISNULL and NULLIF to handle division by zero errors.\u003c/li\u003e\n\u003ch4\u003eMain Query:\u003c/h4\u003e\n\u003cli\u003eSelects the top 10 products by \u003ccode\u003eStockToSalesRatio\u003c/code\u003e.\u003c/li\u003e\n\u003cli\u003eOrders the results by \u003ccode\u003eStockToSalesRatio\u003c/code\u003e in descending order to highlight products with high inventory relative to sales.\u003c/li\u003e \n\u003ch4\u003eComments on Key Metrics:\u003c/h4\u003e\n\u003cli\u003eInventory Turnover Ratio (ITR): Measures how often inventory is sold and replaced over a period. A higher ITR indicates better performance.\u003c/li\u003e\n\u003cli\u003eStock to Sales Ratio (SSR): Compares average inventory to sales. A higher SSR suggests overstocking and potential inefficiencies.\u003c/li\u003e\n\u003cli\u003eThis script identifies products with high inventory but low sales and provide a basis for optimization strategies like targeted promotions, inventory reduction, or restocking adjustments.\u003c/li\u003e\n\u003c/ul\u003e\n\n \u003cli\u003e\u003ch5\u003e Are all the warehouses currently in use still necessary? How can we review warehouses with low or inactive inventory? \u003c/h5\u003e\u003c/li\u003e\n\t\n```sql\nWITH warehouse_inventory AS (\n    SELECT \n        w.warehouseCode, \n        w.warehouseName, \n\t\tCOUNT(DISTINCT o.customerNumber) AS [Number of Active Customers],\n        SUM(p.quantityInStock) AS totalInventory,\n\t\tISNULL(SUM(od.quantityOrdered), 0) AS totalQuantityOrdered,\n        ISNULL(SUM(od.quantityOrdered * od.priceEach) / NULLIF(AVG(p.quantityInStock), 0), 1) AS InventoryTurnOverRatio,\n        ISNULL(AVG(p.quantityInStock) / NULLIF(SUM(od.quantityOrdered * od.priceEach), 0), 1) AS StockToSalesRatio\n    FROM \n        warehouses w\n    LEFT JOIN \n        products p ON w.warehouseCode = p.warehouseCode\n\tLEFT JOIN orderdetails od ON p.productCode = od.productCode\n\tLEFT JOIN orders o ON od.orderNumber = o.orderNumber\n    GROUP BY \n        w.warehouseCode, w.warehouseName--, p.quantityInStock, p.MSRP\n)\nSELECT \n    warehouseCode, \n    warehouseName, \n\t[Number of Active Customers],\n    totalInventory,\n\ttotalQuantityOrdered,\n\tround(cast(InventoryTurnOverRatio as float), 2) as InventoryTurnOverRatio,\n\tround(cast(StockToSalesRatio as float),4) as StockToSalesRatio\nFROM \n    warehouse_inventory\n--WHERE \n  --  totalInventory \u003c 50;\n  ORDER BY StockToSalesRatio DESC;\n```\n\u003ch6\u003eAnswer 2:\u003c/h6\u003e\n\u003cimg width=\"500\" alt=\"Inventory vs Order\" src=\"https://github.com/Glitzzybetty/SQL-Project/assets/130115684/42a8be54-a5a9-4949-8840-723736057ae3\"\u003e\n\u003cul\u003e\n\u003cli\u003eThe SQL uses \u003ch4\u003e CTE i.e. common Table Expression(warehouse_inventory):\u003c/h4\u003e\u003c/li\u003e\n\u003cli\u003eCalculates \u003ccode\u003etotalQuantityOrdered\u003c/code\u003e, \u003ccode\u003eInventoryTurnOverRatio\u003c/code\u003e, and \u003ccode\u003eStockToSalesRatio\u003c/code\u003e.\u003c/li\u003e\n\u003ch4\u003eMain Query:\u003c/h4\u003e\n\u003cli\u003eSelects \u003ccode\u003ewarehouseName\u003c/code\u003e, \u003ccode\u003eNumber of Active Customers\u003c/code\u003e, \u003ccode\u003etotalInventory\u003c/code\u003e.\u003c/l1\u003e\n\u003cli\u003eOrders the results by \u003ccode\u003eStockToSalesRatio\u003c/code\u003e in descending order to highlight warehouses with high inventory relative to sales.\u003c/li\u003e \n\u003ch4\u003eComments on Key Metrics:\u003c/h4\u003e\n\u003cli\u003eHighest SSR on the list implies a high amount of inventory relative to sales.\u003c/li\u003e\n\u003cli\u003eSuggests overstocking, higher holding costs, and potential obsolescence.\u003c/li\u003e\n\u003cli\u003eMay indicate that inventory is not turning over quickly enough, leading to inefficiency.\u003c/li\u003e\n\u003cli\u003e Highest ITR Indicates high inventory turnover.\u003c/li\u003e\n\u003ch4\u003eOptimisation Strategy\u003c/h4\u003e\n\u003cp\u003eTo Increase ITR and reduce SSR:\u003c/p\u003e\n\u003cli\u003e Offer incentives or discounts to move excess inventory.\u003c/li\u003e\n\u003cli\u003eSlow down or temporarily halt new inventory orders until sales catch up with existing stock.\u003c/li\u003e\n\u003cli\u003eAnalyze the reasons for low sales, such as product relevance, competition, or market demand, and take corrective actions.\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003cli\u003e\u003ch5\u003e Is there a relationship between product prices and their sales levels?  How can price adjustments impact sales?  \u003c/h5\u003e\u003c/li\u003e\n\t\n```sql\nSELECT Top 10\n    p.productCode, \n    p.productName, \n    p.MSRP, cast(round(Avg(od.priceEach), 2) as float) as avgPriceSold,\n\tAvg(od.priceEach) - p.MSRP as [Price Diff],\n    SUM(od.quantityOrdered) AS totalQuantitySold\nFROM \n    products p\nJOIN \n    orderdetails od ON p.productCode = od.productCode\nGROUP BY \n    p.productCode, p.productName, p.MSRP\nORDER BY \n    SUM(od.quantityOrdered) desc;\n\n```\n\u003ch6\u003eAnswer 3:\u003c/h6\u003e\n\u003cimg width=\"500\" alt=\"Inventory vs Order\" src=\"https://github.com/Glitzzybetty/SQL-Project/assets/130115684/3e415d16-cfe7-40a0-b726-c9ab91361e01\"\u003e\n\u003cul\u003e\n\u003cli\u003eThis query examines the relationship between product prices (MSRP) i.e. Manufacturer suggested Retail Price and sales volumes.\u003c/li\u003e\n\u003cli\u003eBy analyzing the output, the company can identify if higher prices correspond to lower sales and\u003c/li\u003e\n\u003cli\u003econsider price adjustments to optimize sales volumes.\u003c/li\u003e\n\u003c/ul\u003e\n\u003cli\u003e\u003ch5\u003e Who are the customers contributing the most to sales? How can we focus sales efforts on these valuable customers? \u003c/h5\u003e\u003c/li\u003e\n\t\n```sql\nSELECT TOP 10\n    c.customerNumber, \n    c.customerName, \n\tc.[country],\n    SUM(od.quantityOrdered * p.MSRP) AS totalSales\nFROM \n    customers c\nJOIN \n    orders o ON c.customerNumber = o.customerNumber\nJOIN \n    orderdetails od ON o.orderNumber = od.orderNumber\nJOIN \n    products p ON od.productCode = p.productCode\nGROUP BY \n    c.customerNumber, c.customerName, c.[country]\nORDER BY \n    totalSales DESC\n```\n\u003ch6\u003eAnswer 4:\u003c/h6\u003e\n\u003cimg width=\"500\" alt=\"customer sales\" src=\"https://github.com/Glitzzybetty/SQL-Project/assets/130115684/714c9501-93d3-4c39-9075-490dc4c1b55b\"\u003e\n\u003cul\u003e\n\u003cli\u003eThis query identifies the top 10 customers by total sales.\u003c/li\u003e\n\u003cli\u003eFocusing sales efforts on these valuable customers can involve personalized marketing strategies, loyalty programs, and enhanced customer service.\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/ol\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglitzzybetty%2Fsql-personal-project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglitzzybetty%2Fsql-personal-project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglitzzybetty%2Fsql-personal-project/lists"}