-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsales_analysis.sql
40 lines (37 loc) · 1.11 KB
/
sales_analysis.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- Overall Sales Performance
SELECT
YEAR(OrderDate) AS Year,
MONTH(OrderDate) AS Month,
SUM(s.Quantity * p.UnitPriceUSD) AS Total_Sales
FROM Sales s
JOIN Product p ON s.ProductKey = p.ProductKey
GROUP BY Year, Month
ORDER BY Year, Month;
-- Sales by Product
SELECT
p.ProductName,
SUM(s.Quantity) AS Total_Quantity_Sold,
SUM(s.Quantity * p.UnitPriceUSD) AS Total_Revenue
FROM Sales s
JOIN Product p ON s.ProductKey = p.ProductKey
GROUP BY p.ProductName
ORDER BY Total_Revenue DESC
LIMIT 10;
-- Sales by Store
SELECT
st.StoreKey,
st.Country, st.State, st.SquareMeters,
SUM(s.Quantity * p.UnitPriceUSD) AS Store_Sales
FROM Sales s
JOIN Stores st ON s.StoreKey = st.StoreKey
JOIN Product p ON s.ProductKey = p.ProductKey
GROUP BY st.StoreKey, st.Country, st.State, st.SquareMeters
ORDER BY Store_Sales DESC;
-- Sales by Currency
SELECT
s.CurrencyCode,
SUM(s.Quantity * p.UnitPriceUSD * e.Exchange) AS Total_Sales_Converted
FROM Sales s
JOIN Product p ON s.ProductKey = p.ProductKey
JOIN exchange_rates e ON s.CurrencyCode = e.Currency AND s.OrderDate = e.Date
GROUP BY s.CurrencyCode;