{"id":28509767,"url":"https://github.com/shrunga92/cafe_sales_analysis_sql","last_synced_at":"2026-01-28T20:39:35.758Z","repository":{"id":286223668,"uuid":"960767228","full_name":"shrunga92/Cafe_Sales_Analysis_SQL","owner":"shrunga92","description":"The goal of this project is to analyze the sales data of Monday Coffee, a company that has been selling its products online since January 2023, and to recommend the top three major cities in India for opening new coffee shop locations based on consumer demand and sales performance.","archived":false,"fork":false,"pushed_at":"2025-04-05T03:15:36.000Z","size":194,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-08T22:33:27.998Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/shrunga92.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":"2025-04-05T03:00:07.000Z","updated_at":"2025-04-05T03:15:40.000Z","dependencies_parsed_at":"2025-04-05T04:19:47.867Z","dependency_job_id":"bc5d2130-c6c4-434f-b4e5-ba06e574b3cf","html_url":"https://github.com/shrunga92/Cafe_Sales_Analysis_SQL","commit_stats":null,"previous_names":["shrunga92/cafe_sales_analysis_sql"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shrunga92/Cafe_Sales_Analysis_SQL","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shrunga92%2FCafe_Sales_Analysis_SQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shrunga92%2FCafe_Sales_Analysis_SQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shrunga92%2FCafe_Sales_Analysis_SQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shrunga92%2FCafe_Sales_Analysis_SQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shrunga92","download_url":"https://codeload.github.com/shrunga92/Cafe_Sales_Analysis_SQL/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shrunga92%2FCafe_Sales_Analysis_SQL/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263243659,"owners_count":23436347,"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":[],"created_at":"2025-06-08T22:30:43.275Z","updated_at":"2026-01-28T20:39:35.752Z","avatar_url":"https://github.com/shrunga92.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cafe_Sales_Analysis_SQL\nThe goal of this project is to analyze the sales data of Monday Coffee, a company that has been selling its products online since January 2023, and to recommend the top three major cities in India for opening new coffee shop locations based on consumer demand and sales performance.\n\n\n##  Reports \u0026 Data Analysis\n\n``` sql\n-- Q.1 Coffee Consumers Count\n-- How many people in each city are estimated to consume coffee, given that 25% of the population does?\n\nSELECT \n\tcity_name,\n\tROUND(\n\t(population * 0.25)/1000000, \n\t2) as coffee_consumers_in_millions,\n\tcity_rank\nFROM city\nORDER BY 2 DESC\n\n-- -- Q.2\n-- Total Revenue from Coffee Sales\n-- What is the total revenue generated from coffee sales across all cities in the last quarter of 2023?\n\n\nSELECT \n\tSUM(total) as total_revenue\nFROM sales\nWHERE \n\tEXTRACT(YEAR FROM sale_date)  = 2023\n\tAND\n\tEXTRACT(quarter FROM sale_date) = 4\n\n\n\nSELECT \n\tci.city_name,\n\tSUM(s.total) as total_revenue\nFROM sales as s\nJOIN customers as c\nON s.customer_id = c.customer_id\nJOIN city as ci\nON ci.city_id = c.city_id\nWHERE \n\tEXTRACT(YEAR FROM s.sale_date)  = 2023\n\tAND\n\tEXTRACT(quarter FROM s.sale_date) = 4\nGROUP BY 1\nORDER BY 2 DESC\n\n\n-- Q.3\n-- Sales Count for Each Product\n-- How many units of each coffee product have been sold?\n\nSELECT \n\tp.product_name,\n\tCOUNT(s.sale_id) as total_orders\nFROM products as p\nLEFT JOIN\nsales as s\nON s.product_id = p.product_id\nGROUP BY 1\nORDER BY 2 DESC\n\n-- Q.4\n-- Average Sales Amount per City\n-- What is the average sales amount per customer in each city?\n\n-- city abd total sale\n-- no cx in each these city\n\n\nSELECT \n\tci.city_name,\n\tSUM(s.total) as total_revenue,\n\tCOUNT(DISTINCT s.customer_id) as total_cx,\n\tROUND(\n\t\t\tSUM(s.total)::numeric/\n\t\t\t\tCOUNT(DISTINCT s.customer_id)::numeric\n\t\t\t,2) as avg_sale_pr_cx\n\t\nFROM sales as s\nJOIN customers as c\nON s.customer_id = c.customer_id\nJOIN city as ci\nON ci.city_id = c.city_id\nGROUP BY 1\nORDER BY 2 DESC\n\n\n-- -- Q.5\n-- City Population and Coffee Consumers (25%)\n-- Provide a list of cities along with their populations and estimated coffee consumers.\n-- return city_name, total current cx, estimated coffee consumers (25%)\n\nWITH city_table as \n(\n\tSELECT \n\t\tcity_name,\n\t\tROUND((population * 0.25)/1000000, 2) as coffee_consumers\n\tFROM city\n),\ncustomers_table\nAS\n(\n\tSELECT \n\t\tci.city_name,\n\t\tCOUNT(DISTINCT c.customer_id) as unique_cx\n\tFROM sales as s\n\tJOIN customers as c\n\tON c.customer_id = s.customer_id\n\tJOIN city as ci\n\tON ci.city_id = c.city_id\n\tGROUP BY 1\n)\nSELECT \n\tcustomers_table.city_name,\n\tcity_table.coffee_consumers as coffee_consumer_in_millions,\n\tcustomers_table.unique_cx\nFROM city_table\nJOIN \ncustomers_table\nON city_table.city_name = customers_table.city_name\n\n\n\n-- -- Q6\n-- Top Selling Products by City\n-- What are the top 3 selling products in each city based on sales volume?\n\nSELECT * \nFROM -- table\n(\n\tSELECT \n\t\tci.city_name,\n\t\tp.product_name,\n\t\tCOUNT(s.sale_id) as total_orders,\n\t\tDENSE_RANK() OVER(PARTITION BY ci.city_name ORDER BY COUNT(s.sale_id) DESC) as rank\n\tFROM sales as s\n\tJOIN products as p\n\tON s.product_id = p.product_id\n\tJOIN customers as c\n\tON c.customer_id = s.customer_id\n\tJOIN city as ci\n\tON ci.city_id = c.city_id\n\tGROUP BY 1, 2\n\t-- ORDER BY 1, 3 DESC\n) as t1\nWHERE rank \u003c= 3\n\n\n-- Q.7\n-- Customer Segmentation by City\n-- How many unique customers are there in each city who have purchased coffee products?\n\nSELECT * FROM products;\n\n\n\nSELECT \n\tci.city_name,\n\tCOUNT(DISTINCT c.customer_id) as unique_cx\nFROM city as ci\nLEFT JOIN\ncustomers as c\nON c.city_id = ci.city_id\nJOIN sales as s\nON s.customer_id = c.customer_id\nWHERE \n\ts.product_id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)\nGROUP BY 1\n\n\n-- -- Q.8\n-- Average Sale vs Rent\n-- Find each city and their average sale per customer and avg rent per customer\n\n-- Conclusions\n\nWITH city_table\nAS\n(\n\tSELECT \n\t\tci.city_name,\n\t\tSUM(s.total) as total_revenue,\n\t\tCOUNT(DISTINCT s.customer_id) as total_cx,\n\t\tROUND(\n\t\t\t\tSUM(s.total)::numeric/\n\t\t\t\t\tCOUNT(DISTINCT s.customer_id)::numeric\n\t\t\t\t,2) as avg_sale_pr_cx\n\t\t\n\tFROM sales as s\n\tJOIN customers as c\n\tON s.customer_id = c.customer_id\n\tJOIN city as ci\n\tON ci.city_id = c.city_id\n\tGROUP BY 1\n\tORDER BY 2 DESC\n),\ncity_rent\nAS\n(SELECT \n\tcity_name, \n\testimated_rent\nFROM city\n)\nSELECT \n\tcr.city_name,\n\tcr.estimated_rent,\n\tct.total_cx,\n\tct.avg_sale_pr_cx,\n\tROUND(\n\t\tcr.estimated_rent::numeric/\n\t\t\t\t\t\t\t\t\tct.total_cx::numeric\n\t\t, 2) as avg_rent_per_cx\nFROM city_rent as cr\nJOIN city_table as ct\nON cr.city_name = ct.city_name\nORDER BY 4 DESC\n\n\n\n-- Q.9\n-- Monthly Sales Growth\n-- Sales growth rate: Calculate the percentage growth (or decline) in sales over different time periods (monthly)\n-- by each city\n\nWITH\nmonthly_sales\nAS\n(\n\tSELECT \n\t\tci.city_name,\n\t\tEXTRACT(MONTH FROM sale_date) as month,\n\t\tEXTRACT(YEAR FROM sale_date) as YEAR,\n\t\tSUM(s.total) as total_sale\n\tFROM sales as s\n\tJOIN customers as c\n\tON c.customer_id = s.customer_id\n\tJOIN city as ci\n\tON ci.city_id = c.city_id\n\tGROUP BY 1, 2, 3\n\tORDER BY 1, 3, 2\n),\ngrowth_ratio\nAS\n(\n\t\tSELECT\n\t\t\tcity_name,\n\t\t\tmonth,\n\t\t\tyear,\n\t\t\ttotal_sale as cr_month_sale,\n\t\t\tLAG(total_sale, 1) OVER(PARTITION BY city_name ORDER BY year, month) as last_month_sale\n\t\tFROM monthly_sales\n)\n\nSELECT\n\tcity_name,\n\tmonth,\n\tyear,\n\tcr_month_sale,\n\tlast_month_sale,\n\tROUND(\n\t\t(cr_month_sale-last_month_sale)::numeric/last_month_sale::numeric * 100\n\t\t, 2\n\t\t) as growth_ratio\n\nFROM growth_ratio\nWHERE \n\tlast_month_sale IS NOT NULL\t\n\n\n-- Q.10\n-- Market Potential Analysis\n-- Identify top 3 city based on highest sales, return city name, total sale, total rent, total customers, estimated coffee consumer\n\n\n\nWITH city_table\nAS\n(\n\tSELECT \n\t\tci.city_name,\n\t\tSUM(s.total) as total_revenue,\n\t\tCOUNT(DISTINCT s.customer_id) as total_cx,\n\t\tROUND(\n\t\t\t\tSUM(s.total)::numeric/\n\t\t\t\t\tCOUNT(DISTINCT s.customer_id)::numeric\n\t\t\t\t,2) as avg_sale_pr_cx\n\t\t\n\tFROM sales as s\n\tJOIN customers as c\n\tON s.customer_id = c.customer_id\n\tJOIN city as ci\n\tON ci.city_id = c.city_id\n\tGROUP BY 1\n\tORDER BY 2 DESC\n),\ncity_rent\nAS\n(\n\tSELECT \n\t\tcity_name, \n\t\testimated_rent,\n\t\tROUND((population * 0.25)/1000000, 3) as estimated_coffee_consumer_in_millions\n\tFROM city\n)\nSELECT \n\tcr.city_name,\n\ttotal_revenue,\n\tcr.estimated_rent as total_rent,\n\tct.total_cx,\n\testimated_coffee_consumer_in_millions,\n\tct.avg_sale_pr_cx,\n\tROUND(\n\t\tcr.estimated_rent::numeric/\n\t\t\t\t\t\t\t\t\tct.total_cx::numeric\n\t\t, 2) as avg_rent_per_cx\nFROM city_rent as cr\nJOIN city_table as ct\nON cr.city_name = ct.city_name\nORDER BY 2 DESC\n\n```\n## Recommendations\nAfter analyzing the data, the recommended top three cities for new store openings are:\n\nCity 1: Pune\n\nAverage rent per customer is very low.\n\nHighest total revenue.\n\nAverage sales per customer is also high.\n\nCity 2: Delhi\n\nHighest estimated coffee consumers at 7.7 million.\n\nHighest total number of customers, which is 68.\n\nAverage rent per customer is 330 (still under 500).\n\nCity 3: Jaipur\n\nHighest number of customers, which is 69.\n\nAverage rent per customer is very low at 156.\n\nAverage sales per customer is better at 11.6k.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshrunga92%2Fcafe_sales_analysis_sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshrunga92%2Fcafe_sales_analysis_sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshrunga92%2Fcafe_sales_analysis_sql/lists"}