Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q1: from data warehouse (star schema) write sql quary: DW_Time (Time_id, Month,

ID: 3738503 • Letter: Q

Question

Q1: from data warehouse (star schema) write sql quary:

DW_Time (Time_id, Month, Year)

DW_Customer_Demographics (Dem_id, age_group, min_age, max_age,Gender)

DW_Facts (Time_id, Dem_id, Total_sales_amount, No_of_books_sold)

Design 5-6 age groups for the customers. All customers are at least 18 years old.

Add test data for 2-3 month within 2017

Add test data for 5-6 age groups for both genders

Q2:

if we have a table and what is the sql quary :

Add two “computer books” to the database. Add yourself as a customer and add an order for the above two books.

Calculate the total revenue for each month and year (try ROLLUP and CUBE functions).

Add DOB and Gender to the CUSTOMERS table and add some data.

Calculate the age of the customer as of the order date.

Calculate the age group for the customer.

Calculate the revenue and no of books per customer group, per month and year.

Design a stage-table for the DW upload.

Explanation / Answer

Q1) Answer:

---------------------

CREATE TABLE DW_Time (

Time_id int,

Month varchar(255),

Year varchar(255),

primary key(Time_id)

);

CREATE TABLE DW_Customer_Demographics (

Dem_id int,

age_group int,

min_age int,

max_age int,

Gender varchar(255) ,

primary key(Dem_id)

);

CREATE TABLE DW_Facts (

Time_id int,

Dem_id int,

Total_sales_amount double(255),

No_of_books_sold int,

FOREIGN KEY (Time_id) REFERENCES DW_Time(Time_id)

FOREIGN KEY (Dem_id) REFERENCES DW_Customer_Demographics(Dem_id)

);

---------------------------

Time_id Month Year

---------------------------

1 March 2017

2 August 2017

---------------------------

-----------------------------------------------

Dem_id Age_group min_age max_age gender

-----------------------------------------------

1 28 18 60 Male

2 36 18 60 Female

3 54 18 60 Female

4 47 18 60 Male

5 19 18 60 Male

6 23 18 60 Male

------------------------------------------------

-----------------------------------------------------------

Time_id Dem_id Total_sales_amount No_of_books_sold

-----------------------------------------------------------

1 2 3000 10

2 5 1500 6

3 4 600 2

------------------------------------------------------------