-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11-schema-design-solutions.sql
More file actions
47 lines (43 loc) · 962 Bytes
/
Copy path11-schema-design-solutions.sql
File metadata and controls
47 lines (43 loc) · 962 Bytes
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
-- Solutions 11: Schema Design and Constraints
-- 1.
INSERT INTO lesson_dim_customers (customer_id, customer_name, segment, region)
VALUES ('TEST-CUST-001', 'Practice Customer', 'Consumer', 'West');
-- 2.
INSERT INTO lesson_dim_products (product_id, product_name, category, sub_category)
VALUES ('TEST-PROD-001', 'Practice Product', 'Office Supplies', 'Paper');
-- 3.
INSERT INTO lesson_fact_order_items (
row_id,
order_id,
customer_id,
product_id,
order_date,
sales,
quantity,
discount,
profit
)
VALUES (
999999,
'TEST-ORDER-001',
'TEST-CUST-001',
'TEST-PROD-001',
DATE '2017-01-01',
100.00,
2,
0.10,
20.00
);
-- 4.
SELECT
f.order_id,
c.customer_name,
p.product_name,
f.sales,
f.profit
FROM lesson_fact_order_items f
JOIN lesson_dim_customers c
ON f.customer_id = c.customer_id
JOIN lesson_dim_products p
ON f.product_id = p.product_id
ORDER BY f.order_id;