Professional Documents
Culture Documents
Objective:
design a warehouse database using star schema design
load a data warehouse table using sql against the production table
Background
Heather Sweeney Dodge is a home redesign company that specializes in home remodel. They
give seminars around the country and sell books and video at the seminars. They track
attendance and sales at the seminars in a database. They would like to analyze sales trends and
find out which of their products is most popular and which of their important customers.
1
CST363 Database Assignment 17 Data Warehouse
Response:
The whole code transformed. The select statements, the insert statements, everything changed:
For example:
HSDDW:
2
CST363 Database Assignment 17 Data Warehouse
(2, 'MasterCard'),
(3, 'Cash'),
(4, 'American Express'),
(5, 'PayPal'),
(6, 'Check');
3
CST363 Database Assignment 17 Data Warehouse
);
4
CST363 Database Assignment 17 Data Warehouse
5
CST363 Database Assignment 17 Data Warehouse
6
CST363 Database Assignment 17 Data Warehouse
7
CST363 Database Assignment 17 Data Warehouse
8
CST363 Database Assignment 17 Data Warehouse
/***** SEMINAR
**************************************************************/
9
CST363 Database Assignment 17 Data Warehouse
-- 'Nancy.Jacobs@somewhere.com'
INSERT INTO CONTACT VALUES(1, 1, '2013-10-12', 'Seminar', 1);
-- 'Chantel.Jacobs@somewhere.com'
INSERT INTO CONTACT VALUES(2, 1, '2013-10-12', 'Seminar', 1);
-- 'Ralph.Able@somewhere.com'
INSERT INTO CONTACT VALUES(3, 1, '2013-10-12', 'Seminar', 1);
-- 'Susan.Baker@elsewhere.com'
INSERT INTO CONTACT VALUES(4, 1, '2013-10-12', 'Seminar', 1);
10
CST363 Database Assignment 17 Data Warehouse
-- 'Sam.Eagleton@elsewhere.com'
INSERT INTO CONTACT VALUES(5, 1, '2013-10-12', 'Seminar', 1);
-- 'Nancy.Jacobs@somewhere.com',
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(1, 2, '2013-10-15', 'EmailSeminarMessage');
-- 'Chantel.Jacobs@somewhere.com'
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(2, 2, '2013-10-15', 'EmailSeminarMessage');
-- 'Ralph.Able@somewhere.com'
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(3, 2, '2013-10-15', 'EmailSeminarMessage');
-- 'Susan.Baker@elsewhere.com'
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(4, 2, '2013-10-15', 'EmailSeminarMessage');
-- 'Sam.Eagleton@elsewhere.com'
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(5, 2, '2013-10-15', 'EmailSeminarMessage');
-- 'Nancy.Jacobs@somewhere.com',
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(1, 3, '2013-10-15', 'FormLetterSeminar');
-- 'Chantel.Jacobs@somewhere.com'
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(2, 3, '2013-10-15', 'FormLetterSeminar');
-- 'Ralph.Able@somewhere.com'
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(3, 3, '2013-10-15', 'FormLetterSeminar');
-- 'Susan.Baker@elsewhere.com'
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(4, 3, '2013-10-15', 'FormLetterSeminar');
-- 'Sam.Eagleton@elsewhere.com'
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(5, 3, '2013-10-15', 'FormLetterSeminar');
-- 'Kathy.Foxtrot@somewhere.com'
INSERT INTO CONTACT VALUES(6, 1, '2013-10-26', 'Seminar', 2);
-- 'Sally.George@somewhere.com'
INSERT INTO CONTACT VALUES(7, 1, '2013-10-26', 'Seminar', 2);
-- 'Shawn.Hullett@elsewhere.com'
INSERT INTO CONTACT VALUES(8, 1, '2013-10-26', 'Seminar', 2);
-- 'Kathy.Foxtrot@somewhere.com'
11
CST363 Database Assignment 17 Data Warehouse
-- 'Kathy.Foxtrot@somewhere.com'
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(6, 3, '2013-10-30', 'FormLetterSeminar');
-- 'Sally.George@somewhere.com'
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(7, 3, '2013-10-30', 'FormLetterSeminar');
-- 'Shawn.Hullett@elsewhere.com'
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(8, 3, '2013-10-30', 'FormLetterSeminar');
-- 'Bobbi.Pearson@elsewhere.com'
INSERT INTO CONTACT VALUES(9, 1, '2013-11-02', 'Seminar', 3);
-- 'Terry.Ranger@somewhere.com'
INSERT INTO CONTACT VALUES(10, 1, '2013-11-02', 'Seminar', 3);
-- 'Bobbi.Pearson@elsewhere.com'
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(9, 2, '2013-11-06', 'EmailSeminarMessage');
-- 'Terry.Ranger@somewhere.com'
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(10, 2, '2013-11-06', 'EmailSeminarMessage');
-- 'Bobbi.Pearson@elsewhere.com'
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(9, 3, '2013-11-06', 'FormLetterSeminar');
-- 'Terry.Ranger@somewhere.com'
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(10, 3, '2013-11-06', 'FormLetterSeminar');
-- 'Ralph.Able@somewhere.com'
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
VALUES(3, 4, '2014-02-20', 'WebAccountCreation');
-- 'Ralph.Able@somewhere.com'
INSERT INTO CONTACT (CustomerID, ContactNumber, ContactDate, ContactType)
12
CST363 Database Assignment 17 Data Warehouse
-- 'Kathy.Foxtrot@somewhere.com'
INSERT INTO CONTACT VALUES(6, 6, '2014-03-22', 'Seminar', 4);
-- 'Sally.George@somewhere.com'
INSERT INTO CONTACT VALUES(7, 6, '2014-03-22', 'Seminar', 4);
-- 'Jenny.Tyler@somewhere.com'
INSERT INTO CONTACT VALUES(11, 1, '2014-03-22', 'Seminar', 4);
-- 'Joan.Wayne@elsewhere.com'
INSERT INTO CONTACT VALUES(12, 1, '2014-03-22', 'Seminar', 4);
13
CST363 Database Assignment 17 Data Warehouse
14
CST363 Database Assignment 17 Data Warehouse
15
CST363 Database Assignment 17 Data Warehouse
16
CST363 Database Assignment 17 Data Warehouse
Create the SALEs_FOR_RFM table to the HSD-DW database using the create table
statement below. RFM refers to “Recency, Frequency, Monetary Value” which are ways
to identify important customers.
17
CST363 Database Assignment 17 Data Warehouse
2. What data will be used to load the SALES_FOR_RFM fact able? Write the complete
set of SQL statements necessary to load the data. Then run the insert statement to
populate the SALES_FOR_RFM table. Your INSERT statement will be similar to
the load product sales INSERT statement on line 124 of Assignment 7 HSDDW
CreateTablesWithData.sql
Response:
The data needed are the TimeId, the CustomerId, the InvoiceNumber and the preTaxTotslSales.
18
CST363 Database Assignment 17 Data Warehouse
In the above query, product_sales table is called the fact table; customer, timeline
and product tables are called dimension tables.
3. Modify the above query to report the total dollar amount of each product for each
year instead of the quantity sold for each product. Create an SQL View equivalent
of the SQL query you wrote. Use your view and verify that the view returns the same
number of rows in the same order as your sql SELECT.
Copy and paste your SQL create view statement below.
Modified query:
19
CST363 Database Assignment 17 Data Warehouse
20
CST363 Database Assignment 17 Data Warehouse
Response:
Below is the product sales table with the paymentid added
21
CST363 Database Assignment 17 Data Warehouse
);
Below is the modified insert and select query with paymentid added:
22