{"id":25403349,"url":"https://github.com/ayonika2001/pizza_sales_sql_project","last_synced_at":"2025-04-12T15:13:37.386Z","repository":{"id":276017753,"uuid":"927942378","full_name":"Ayonika2001/Pizza_Sales_SQL_Project","owner":"Ayonika2001","description":"This SQL project models a Pizza Hut database, tracking orders, order details, and pizza types. It includes queries for calculating total orders, revenue, pizza popularity, and category-wise distributions, providing insights into sales trends and pizza preferences.","archived":false,"fork":false,"pushed_at":"2025-02-05T19:57:05.000Z","size":331,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T15:13:33.083Z","etag":null,"topics":["csv","dbms","mysql","mysqldatabase","mysqlserver","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/Ayonika2001.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-02-05T19:49:00.000Z","updated_at":"2025-02-05T20:03:49.000Z","dependencies_parsed_at":"2025-02-05T20:54:30.181Z","dependency_job_id":"535097a2-a48c-4ba2-8bf1-2e294c5bbe55","html_url":"https://github.com/Ayonika2001/Pizza_Sales_SQL_Project","commit_stats":null,"previous_names":["ayonika2001/pizza_sales_sql_project"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ayonika2001%2FPizza_Sales_SQL_Project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ayonika2001%2FPizza_Sales_SQL_Project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ayonika2001%2FPizza_Sales_SQL_Project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ayonika2001%2FPizza_Sales_SQL_Project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ayonika2001","download_url":"https://codeload.github.com/Ayonika2001/Pizza_Sales_SQL_Project/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586244,"owners_count":21128998,"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":["csv","dbms","mysql","mysqldatabase","mysqlserver","sql"],"created_at":"2025-02-16T02:38:33.262Z","updated_at":"2025-04-12T15:13:37.361Z","avatar_url":"https://github.com/Ayonika2001.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"## Pizza Hut SQL Analysis Project\n\n### 📌 Project Overview\nThis project provides an in-depth SQL analysis of a **Pizza Hut** database to extract valuable insights, such as order statistics, revenue generation, pizza popularity, and sales distribution. It consists of various SQL queries categorized into **Basic, Intermediate, and Advanced** levels to explore different aspects of the pizza sales data.\n\n---\n\n### 📂 Database Schema\n\n#### **1. `orders` Table**\nStores details of orders placed.\n\n```sql\nCREATE TABLE orders (\n    order_id INT PRIMARY KEY,\n    order_date DATE NOT NULL,\n    order_time TIME NOT NULL\n);\n```\n\n#### **2. `order_details` Table**\nStores details of individual pizzas ordered.\n\n```sql\nCREATE TABLE order_details (\n    order_details_id INT PRIMARY KEY,\n    order_id INT NOT NULL,\n    pizza_id TEXT NOT NULL,\n    quantity INT NOT NULL\n);\n```\n\n---\n\n## 🛠 SQL Queries\n\n### 🔹 Basic Queries\n\n#### **1. Retrieve the total number of orders placed**\n```sql\nSELECT COUNT(order_id) AS total_orders FROM orders;\n```\n\n#### **2. Calculate the total revenue generated from pizza sales**\n```sql\nSELECT ROUND(SUM(order_details.quantity * pizzas.price), 0) AS total_revenue\nFROM order_details \nJOIN pizzas ON order_details.pizza_id = pizzas.pizza_id;\n```\n\n#### **3. Identify the highest-priced pizza**\n```sql\nSELECT pizza_types.name, MAX(pizzas.price) AS highest_priced_pizza\nFROM pizza_types \nJOIN pizzas ON pizza_types.pizza_type_id = pizzas.pizza_type_id\nGROUP BY pizza_types.name \nORDER BY highest_priced_pizza DESC \nLIMIT 1;\n```\n\n#### **4. Identify the most common pizza size ordered**\n```sql\nSELECT pizzas.size, COUNT(order_details.order_details_id) AS most_common_pizza_size_ordered\nFROM pizzas \nJOIN order_details ON pizzas.pizza_id = order_details.pizza_id\nGROUP BY pizzas.size\nORDER BY most_common_pizza_size_ordered DESC \nLIMIT 1;\n```\n\n#### **5. List the top 5 most ordered pizza types along with their quantities**\n```sql\nSELECT pizza_types.name, SUM(order_details.quantity) AS most_ordered_pizza\nFROM pizza_types \nJOIN pizzas ON pizza_types.pizza_type_id = pizzas.pizza_type_id\nJOIN order_details ON order_details.pizza_id = pizzas.pizza_id\nGROUP BY pizza_types.name\nORDER BY most_ordered_pizza DESC \nLIMIT 5;\n```\n\n---\n\n### 🔹 Intermediate Queries\n\n#### **1. Find the total quantity of each pizza category ordered**\n```sql\nSELECT pizza_types.category, SUM(order_details.quantity) AS total_quantity\nFROM pizza_types \nJOIN pizzas ON pizza_types.pizza_type_id = pizzas.pizza_type_id\nJOIN order_details ON order_details.pizza_id = pizzas.pizza_id\nGROUP BY pizza_types.category;\n```\n\n#### **2. Determine the distribution of orders by hour of the day**\n```sql\nSELECT HOUR(orders.order_time) AS order_hour, COUNT(order_id) AS total_orders\nFROM orders \nGROUP BY HOUR(orders.order_time);\n```\n\n#### **3. Find the category-wise distribution of pizzas**\n```sql\nSELECT category, COUNT(name) AS pizza_count\nFROM pizza_types\nGROUP BY category;\n```\n\n#### **4. Calculate the average number of pizzas ordered per day**\n```sql\nSELECT ROUND(AVG(quantity), 0) AS avg_pizzas_per_day\nFROM (\n    SELECT orders.order_date, SUM(order_details.quantity) AS quantity\n    FROM orders \n    JOIN order_details ON orders.order_id = order_details.order_id\n    GROUP BY orders.order_date\n) AS order_quantity;\n```\n\n#### **5. Determine the top 3 most ordered pizza types based on revenue**\n```sql\nSELECT pizza_types.name, ROUND(SUM(order_details.quantity * pizzas.price), 0) AS total_revenue\nFROM pizza_types \nJOIN pizzas ON pizza_types.pizza_type_id = pizzas.pizza_type_id\nJOIN order_details ON order_details.pizza_id = pizzas.pizza_id\nGROUP BY pizza_types.name\nORDER BY total_revenue DESC \nLIMIT 3;\n```\n\n---\n\n### 🔹 Advanced Queries\n\n#### **1. Calculate the percentage contribution of each pizza type to total revenue**\n```sql\nSELECT pizza_types.name,\n    ROUND(SUM(order_details.quantity * pizzas.price) / \n    (SELECT ROUND(SUM(order_details.quantity * pizzas.price), 2)\n     FROM order_details \n     JOIN pizzas ON order_details.pizza_id = pizzas.pizza_id) * 100, 2) AS revenue_percentage\nFROM pizza_types \nJOIN pizzas ON pizza_types.pizza_type_id = pizzas.pizza_type_id\nJOIN order_details ON order_details.pizza_id = pizzas.pizza_id\nGROUP BY pizza_types.name;\n```\n\n#### **2. Analyze the cumulative revenue generated over time**\n```sql\nSELECT order_date,\n       SUM(total_revenue) OVER (ORDER BY order_date) AS cumulative_revenue\nFROM (\n    SELECT orders.order_date, ROUND(SUM(order_details.quantity * pizzas.price), 0) AS total_revenue\n    FROM order_details \n    JOIN pizzas ON order_details.pizza_id = pizzas.pizza_id\n    JOIN orders ON orders.order_id = order_details.order_id\n    GROUP BY orders.order_date\n) AS total_sales;\n```\n\n#### **3. Determine the top 3 most ordered pizza types based on revenue for each pizza category**\n```sql\nWITH ranked_pizza_types AS (\n    SELECT pizza_types.name, pizza_types.category,\n           SUM(order_details.quantity * pizzas.price) AS total_revenue,\n           RANK() OVER (PARTITION BY pizza_types.category ORDER BY SUM(order_details.quantity * pizzas.price) DESC) AS rnk\n    FROM order_details \n    JOIN pizzas ON order_details.pizza_id = pizzas.pizza_id\n    JOIN pizza_types ON pizza_types.pizza_type_id = pizzas.pizza_type_id\n    GROUP BY pizza_types.name, pizza_types.category\n)\nSELECT name, category, total_revenue, rnk\nFROM ranked_pizza_types\nWHERE rnk \u003c= 3;\n```\n\n---\n\n## 📌 Conclusion\nThis project utilizes **SQL queries** to analyze pizza sales data effectively. By leveraging **JOINs, GROUP BY, aggregate functions, window functions, and ranking**, we uncover valuable insights that can help optimize sales and inventory management.\n\n---\n\n## 📜 Author\n**Project by:** Ayonika Dutta\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayonika2001%2Fpizza_sales_sql_project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fayonika2001%2Fpizza_sales_sql_project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayonika2001%2Fpizza_sales_sql_project/lists"}