|
| 1 | +/* |
| 2 | +=============================================================================== |
| 3 | +Measures Exploration (Key Metrics) |
| 4 | +=============================================================================== |
| 5 | +Purpose: |
| 6 | + - To calculate aggregated metrics (e.g., totals, averages) for quick insights. |
| 7 | + - To identify overall trends or spot anomalies. |
| 8 | +
|
| 9 | +SQL Functions Used: |
| 10 | + - COUNT(), SUM(), AVG() |
| 11 | +=============================================================================== |
| 12 | +*/ |
| 13 | + |
| 14 | +-- Find the Total Sales |
| 15 | +SELECT SUM(sales_amount) AS total_sales FROM gold.fact_sales |
| 16 | + |
| 17 | +-- Find how many items are sold |
| 18 | +SELECT SUM(quantity) AS total_quantity FROM gold.fact_sales |
| 19 | + |
| 20 | +-- Find the average selling price |
| 21 | +SELECT AVG(price) AS avg_price FROM gold.fact_sales |
| 22 | + |
| 23 | +-- Find the Total number of Orders |
| 24 | +SELECT COUNT(order_number) AS total_orders FROM gold.fact_sales |
| 25 | +SELECT COUNT(DISTINCT order_number) AS total_orders FROM gold.fact_sales |
| 26 | + |
| 27 | +-- Find the total number of products |
| 28 | +SELECT COUNT(product_name) AS total_products FROM gold.dim_products |
| 29 | + |
| 30 | +-- Find the total number of customers |
| 31 | +SELECT COUNT(customer_key) AS total_customers FROM gold.dim_customers; |
| 32 | + |
| 33 | +-- Find the total number of customers that has placed an order |
| 34 | +SELECT COUNT(DISTINCT customer_key) AS total_customers FROM gold.fact_sales; |
| 35 | + |
| 36 | +-- Generate a Report that shows all key metrics of the business |
| 37 | +SELECT 'Total Sales' AS measure_name, SUM(sales_amount) AS measure_value FROM gold.fact_sales |
| 38 | +UNION ALL |
| 39 | +SELECT 'Total Quantity', SUM(quantity) FROM gold.fact_sales |
| 40 | +UNION ALL |
| 41 | +SELECT 'Average Price', AVG(price) FROM gold.fact_sales |
| 42 | +UNION ALL |
| 43 | +SELECT 'Total Orders', COUNT(DISTINCT order_number) FROM gold.fact_sales |
| 44 | +UNION ALL |
| 45 | +SELECT 'Total Products', COUNT(DISTINCT product_name) FROM gold.dim_products |
| 46 | +UNION ALL |
| 47 | +SELECT 'Total Customers', COUNT(customer_key) FROM gold.dim_customers; |
0 commit comments