-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLQueryStarSchema & Data Marts.sql
101 lines (87 loc) · 2.11 KB
/
SQLQueryStarSchema & Data Marts.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
--Creating Star schema for further Work
USE Staging
--Checking The joins Working or not
SELECT
DF.customer_id,
DF.order_id,
DF.order_status,
rd.review_score,
DC.customer_city,
DC.customer_state,
DP.Payment_type,
DP.Payment_installments,
OID.shipping_limit_date,
DF.order_estimated_delivery_date,
DF.order_purchase_timestamp,
rd.review_creation_data_timestamp
FROM
orders_dataFACT DF
JOIN order_review_dataDIM rd ON DF.order_id = rd.order_id
JOIN customer_dataDIM DC ON DF.customer_id = DC.customer_id
JOIN order_payment_dataDIM DP ON DF.order_id = DP.order_id
JOIN order_item_dataDim OID ON DF.order_id = OID.order_id;
-- Create a view for the star schema
CREATE VIEW StarSchema AS
SELECT
DF.customer_id,
DF.order_id,
DF.order_status,
OID.seller_id,
rd.review_score,
DC.customer_city,
DC.customer_state,
DP.Payment_type,
DP.Payment_installments,
OID.shipping_limit_date,
DF.order_estimated_delivery_date,
DF.order_approved_at,
DF.order_delivered_customer_date,
DF.order_purchase_timestamp,
rd.review_creation_data_timestamp
FROM
orders_dataFACT DF
JOIN
order_review_dataDIM rd ON DF.order_id = rd.order_id
JOIN
customer_dataDIM DC ON DF.customer_id = DC.customer_id
JOIN
order_payment_dataDIM DP ON DF.order_id = DP.order_id
JOIN
order_item_dataDim OID ON DF.order_id = OID.order_id;
--Testing StarSchema
SELECT *
FROM StarSchema;
CREATE VIEW PowerBI_DataMart AS
SELECT
customer_id,
order_id,
seller_id,
customer_city,
customer_state,
order_status,
Payment_type,
review_score,
order_purchase_timestamp,
order_estimated_delivery_date,
shipping_limit_date
FROM
StarSchema
--Testing Power BI Data mart
Select * from dbo.PowerBI_DataMart;
--Creating ML Data Mart
CREATE VIEW MLPrediction_DataMart AS
SELECT
order_id,
customer_id,
customer_state,
Payment_type,
order_status,
review_score,
shipping_limit_date,
order_purchase_timestamp,
order_approved_at,
order_estimated_delivery_date,
order_delivered_customer_date
FROM dbo.StarSchema
--CHECKING FOR MLPrediction working
SELECT * FROM MLPrediction_DataMart;