Repository navigation
Expand file tree
/
Copy pathweather_impact_retail.sql
More file actions
81 lines (70 loc) · 2.65 KB
/
Copy pathweather_impact_retail.sql
File metadata and controls
81 lines (70 loc) · 2.65 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Weather Impact on Retail Demo
*
* Scenario:
* Correlating daily sales with local weather conditions.
* Architecture: Medallion (Bronze -> Silver -> Gold)
* Goal: Optimize inventory for weather-driven demand (e.g., umbrellas, sunscreen).
*/
-------------------------------------------------------------------------------
-- 0. SETUP
-------------------------------------------------------------------------------
CREATE FOLDER IF NOT EXISTS WeatherRetailDB;
CREATE FOLDER IF NOT EXISTS WeatherRetailDB.Bronze;
CREATE FOLDER IF NOT EXISTS WeatherRetailDB.Silver;
CREATE FOLDER IF NOT EXISTS WeatherRetailDB.Gold;
-------------------------------------------------------------------------------
-- 1. BRONZE LAYER
-------------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS WeatherRetailDB.Bronze.WeatherLog (
City VARCHAR,
"Date" DATE,
Condition VARCHAR, -- 'Sunny', 'Rain', 'Snow'
AvgTempC DOUBLE
);
CREATE TABLE IF NOT EXISTS WeatherRetailDB.Bronze.StoreSales (
StoreID INT,
City VARCHAR,
"Date" DATE,
Category VARCHAR,
Revenue DOUBLE
);
INSERT INTO WeatherRetailDB.Bronze.WeatherLog VALUES
('New York', '2025-04-01', 'Rain', 10.0),
('Los Angeles', '2025-04-01', 'Sunny', 25.0);
INSERT INTO WeatherRetailDB.Bronze.StoreSales VALUES
(1, 'New York', '2025-04-01', 'Umbrellas', 5000.0),
(1, 'New York', '2025-04-01', 'Ice Cream', 200.0),
(2, 'Los Angeles', '2025-04-01', 'Umbrellas', 0.0),
(2, 'Los Angeles', '2025-04-01', 'Ice Cream', 4000.0);
-------------------------------------------------------------------------------
-- 2. SILVER LAYER
-------------------------------------------------------------------------------
CREATE OR REPLACE VIEW WeatherRetailDB.Silver.SalesVsWeather AS
SELECT
s."Date",
s.City,
w.Condition,
w.AvgTempC,
s.Category,
s.Revenue
FROM WeatherRetailDB.Bronze.StoreSales s
JOIN WeatherRetailDB.Bronze.WeatherLog w
ON s.City = w.City AND s."Date" = w."Date";
-------------------------------------------------------------------------------
-- 3. GOLD LAYER
-------------------------------------------------------------------------------
CREATE OR REPLACE VIEW WeatherRetailDB.Gold.CategorySensitivity AS
SELECT
Category,
Condition,
AVG(Revenue) AS AvgRevenue
FROM WeatherRetailDB.Silver.SalesVsWeather
GROUP BY Category, Condition;
-------------------------------------------------------------------------------
-- 4. AGENT PROMPTS
-------------------------------------------------------------------------------
/*
PROMPT:
"Which weather Condition drives the highest AvgRevenue for 'Umbrellas' in WeatherRetailDB.Gold.CategorySensitivity?"
*/