-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDDL_Fact_Dim.sql
59 lines (53 loc) · 891 Bytes
/
DDL_Fact_Dim.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
CREATE OR REPLACE TABLE dim_users AS (
SELECT
user_id
FROM
orders
);
CREATE OR REPLACE TABLE dim_products AS (
SELECT
product_id,
product_name
FROM
products
);
CREATE OR REPLACE TABLE dim_aisles AS (
SELECT
aisle_id,
aisle
FROM
aisles
);
CREATE OR REPLACE TABLE dim_departments AS (
SELECT
department_id,
department
FROM
departments
);
CREATE OR REPLACE TABLE dim_orders AS (
SELECT
order_id,
order_number,
order_dow,
order_hour_of_day,
days_since_prior_order
FROM
orders
);
CREATE OR REPLACE TABLE fact_order_products AS (
SELECT
op.order_id,
op.product_id,
o.user_id,
p.department_id,
p.aisle_id,
op.add_to_cart_order,
op.reordered
FROM
order_products op
JOIN
orders o ON op.order_id = o.order_id
JOIN
products p ON op.product_id = p.product_id
);