Last active
June 7, 2022 18:43
-
-
Save prmoore77/9d2565ed748cce84c8e50f4b10ba27dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE sales_facts ( | |
product_id INTEGER NOT NULL | |
, customer_id VARCHAR (100) NOT NULL | |
, date_id DATE NOT NULL | |
, unit_quantity NUMERIC NOT NULL | |
, sales_amount NUMERIC NOT NULL | |
) | |
; | |
INSERT INTO sales_facts (product_id, customer_id, date_id, unit_quantity, sales_amount) | |
VALUES ((SELECT node_natural_key | |
FROM product_nodes | |
WHERE node_name = 'Hershey Bar') | |
, 'Phil' | |
, DATE '2022-01-01' | |
, 1 | |
, 3.00 | |
); | |
INSERT INTO sales_facts (product_id, customer_id, date_id, unit_quantity, sales_amount) | |
VALUES ((SELECT node_natural_key | |
FROM product_nodes | |
WHERE node_name = 'Hershey Bar') | |
, 'Lottie' | |
, DATE '2022-01-02' | |
, 5 | |
, 15.00 | |
); | |
INSERT INTO sales_facts (product_id, customer_id, date_id, unit_quantity, sales_amount) | |
VALUES ((SELECT node_natural_key | |
FROM product_nodes | |
WHERE node_name = 'Nerds') | |
, 'Kalie' | |
, DATE '2022-01-02' | |
, 2 | |
, 5.00 | |
); | |
INSERT INTO sales_facts (product_id, customer_id, date_id, unit_quantity, sales_amount) | |
VALUES ((SELECT node_natural_key | |
FROM product_nodes | |
WHERE node_name = 'Tomatoes') | |
, 'Phil' | |
, DATE '2022-01-02' | |
, 2 | |
, 2.00 | |
); | |
INSERT INTO sales_facts (product_id, customer_id, date_id, unit_quantity, sales_amount) | |
VALUES ((SELECT node_natural_key | |
FROM product_nodes | |
WHERE node_name = 'Spinach') | |
, 'Popeye' | |
, DATE '2022-01-03' | |
, 10 | |
, 5.00 | |
); | |
INSERT INTO sales_facts (product_id, customer_id, date_id, unit_quantity, sales_amount) | |
VALUES ((SELECT node_natural_key | |
FROM product_nodes | |
WHERE node_name = 'Spinach') | |
, 'Brutus' | |
, DATE '2022-01-04' | |
, 1 | |
, 0.50 | |
); | |
INSERT INTO sales_facts (product_id, customer_id, date_id, unit_quantity, sales_amount) | |
VALUES ((SELECT node_natural_key | |
FROM product_nodes | |
WHERE node_name = 'Spinach') | |
, 'Lottie' | |
, DATE '2022-01-04' | |
, 1 | |
, 0.50 | |
); | |
INSERT INTO sales_facts (product_id, customer_id, date_id, unit_quantity, sales_amount) | |
VALUES ((SELECT node_natural_key | |
FROM product_nodes | |
WHERE node_name = 'Spinach') | |
, 'Phil' | |
, DATE '2022-01-05' | |
, 2 | |
, 2.00 | |
); | |
-- Show the sales_facts contents (join to Product for descriptions) | |
SELECT product_nodes.node_name AS product_name | |
, sales_facts.* | |
FROM sales_facts | |
JOIN | |
product_nodes | |
ON sales_facts.product_id = product_nodes.node_natural_key; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment