Repository navigation
Expand file tree
/
Copy pathrestaurant_menu_engineering.sql
More file actions
85 lines (74 loc) · 2.91 KB
/
Copy pathrestaurant_menu_engineering.sql
File metadata and controls
85 lines (74 loc) · 2.91 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
82
83
84
85
/*
* Restaurant Menu Engineering Demo
*
* Scenario:
* Categorizing menu items based on profitability and popularity (Stars, Plowhorses, Puzzles, Dogs).
* Architecture: Medallion (Bronze -> Silver -> Gold)
* Goal: Optimize menu pricing and layout.
*/
-------------------------------------------------------------------------------
-- 0. SETUP
-------------------------------------------------------------------------------
CREATE FOLDER IF NOT EXISTS RestaurantDB;
CREATE FOLDER IF NOT EXISTS RestaurantDB.Bronze;
CREATE FOLDER IF NOT EXISTS RestaurantDB.Silver;
CREATE FOLDER IF NOT EXISTS RestaurantDB.Gold;
-------------------------------------------------------------------------------
-- 1. BRONZE LAYER
-------------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS RestaurantDB.Bronze.MenuItems (
ItemID INT,
Name VARCHAR,
Cost DOUBLE,
Price DOUBLE,
Category VARCHAR -- 'Main', 'Appetizer', 'Dessert'
);
CREATE TABLE IF NOT EXISTS RestaurantDB.Bronze.DailySales (
SalesID INT,
ItemID INT,
Date DATE,
QuantitySold INT
);
INSERT INTO RestaurantDB.Bronze.MenuItems VALUES
(1, 'Signature Burger', 5.00, 15.00, 'Main'),
(2, 'Lobster Bisque', 8.00, 12.00, 'Appetizer'),
(3, 'Fries', 0.50, 5.00, 'Side');
INSERT INTO RestaurantDB.Bronze.DailySales VALUES
(1, 1, '2025-05-01', 100), -- High vol
(2, 2, '2025-05-01', 10), -- Low vol
(3, 3, '2025-05-01', 150); -- High vol
-------------------------------------------------------------------------------
-- 2. SILVER LAYER
-------------------------------------------------------------------------------
CREATE OR REPLACE VIEW RestaurantDB.Silver.ItemAnalysis AS
SELECT
m.Name,
m.Category,
SUM(d.QuantitySold) AS TotalSold,
(m.Price - m.Cost) AS ContributionMargin,
SUM(d.QuantitySold) * (m.Price - m.Cost) AS TotalProfit
FROM RestaurantDB.Bronze.MenuItems m
JOIN RestaurantDB.Bronze.DailySales d ON m.ItemID = d.ItemID
GROUP BY m.Name, m.Category, m.Price, m.Cost;
-------------------------------------------------------------------------------
-- 3. GOLD LAYER
-------------------------------------------------------------------------------
CREATE OR REPLACE VIEW RestaurantDB.Gold.MenuMatrix AS
SELECT
Name,
TotalSold,
ContributionMargin,
CASE
WHEN TotalSold > 50 AND ContributionMargin > 8 THEN 'Star' -- High Pop, High Profit
WHEN TotalSold > 50 AND ContributionMargin <= 8 THEN 'Plowhorse' -- High Pop, Low Profit
WHEN TotalSold <= 50 AND ContributionMargin > 8 THEN 'Puzzle' -- Low Pop, High Profit
ELSE 'Dog' -- Low Pop, Low Profit
END AS Classification
FROM RestaurantDB.Silver.ItemAnalysis;
-------------------------------------------------------------------------------
-- 4. AGENT PROMPTS
-------------------------------------------------------------------------------
/*
PROMPT:
"List all items classified as 'Star' in RestaurantDB.Gold.MenuMatrix."
*/