From 81b38f3c8a212b0428e094febf4140e2a86fc0e5 Mon Sep 17 00:00:00 2001 From: Harshal Narkhede <112054214+Harshal-Narkhede@users.noreply.github.com> Date: Sun, 2 Nov 2025 11:35:01 +0530 Subject: [PATCH] Add files via upload --- magnitude_analysis.sql | 81 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 magnitude_analysis.sql diff --git a/magnitude_analysis.sql b/magnitude_analysis.sql new file mode 100644 index 0000000..3c22ccd --- /dev/null +++ b/magnitude_analysis.sql @@ -0,0 +1,81 @@ +/* +=============================================================================== +Magnitude Analysis +=============================================================================== +Purpose: + - To quantify data and group results by specific dimensions. + - For understanding data distribution across categories. + +SQL Functions Used: + - Aggregate Functions: SUM(), COUNT(), AVG() + - GROUP BY, ORDER BY +=============================================================================== +*/ + +-- Find total customers by countries +SELECT + country, + COUNT(customer_key) AS total_customers +FROM gold.dim_customers +GROUP BY country +ORDER BY total_customers DESC; + +-- Find total customers by gender +SELECT + gender, + COUNT(customer_key) AS total_customers +FROM gold.dim_customers +GROUP BY gender +ORDER BY total_customers DESC; + +-- Find total products by category +SELECT + category, + COUNT(product_key) AS total_products +FROM gold.dim_products +GROUP BY category +ORDER BY total_products DESC; + +-- What is the average costs in each category? +SELECT + category, + AVG(cost) AS avg_cost +FROM gold.dim_products +GROUP BY category +ORDER BY avg_cost DESC; + +-- What is the total revenue generated for each category? +SELECT + p.category, + SUM(f.sales_amount) AS total_revenue +FROM gold.fact_sales f +LEFT JOIN gold.dim_products p + ON p.product_key = f.product_key +GROUP BY p.category +ORDER BY total_revenue DESC; + + +-- What is the total revenue generated by each customer? +SELECT + c.customer_key, + c.first_name, + c.last_name, + SUM(f.sales_amount) AS total_revenue +FROM gold.fact_sales f +LEFT JOIN gold.dim_customers c + ON c.customer_key = f.customer_key +GROUP BY + c.customer_key, + c.first_name, + c.last_name +ORDER BY total_revenue DESC; + +-- What is the distribution of sold items across countries? +SELECT + c.country, + SUM(f.quantity) AS total_sold_items +FROM gold.fact_sales f +LEFT JOIN gold.dim_customers c + ON c.customer_key = f.customer_key +GROUP BY c.country +ORDER BY total_sold_items DESC;