Star Schema, Dummy Data, and Business Question
Star Schema, Dummy Data, and Business Question
Disusun Oleh:
Kelompok 4
Alvian Eka Maulana 05211640000047
Dani Hadi Saputro 05211640000068
Muslikh Annur Meiviananda 05211640000092
Fathoni Nur Muhammad 05211640000093
Ahmad Naufal Rofif 05211640000113
Dosen Pengampu:
Rully Agus Hendrawan, S. Kom, M. Sc
2
1. Membuat Logical Data Model
Berikut adalah Star Schema Kami:
1
Logical Data Model Customer_Rep_Sales Fact
2
Gabungan Dari Semua Star Schema
Tabel addresses
Tabel customer_demographics
Tabel customer_invoices
3
Tabel customer_rep_sales
Tabel customer_sales
Tabel customers
Tabel geographic_boundaries
Tabel internal_organizations
Tabel product_sales
4
Tabel product
Tabel sales_reps
Tabel time_by_day
Tabel time_by_month
5
View:
What was the sales volume for a category of products for a specific time period?
Query:
SELECT product_sales.product_id,
product_sales.quantity,
time_by_month.fiscal_year,
time_by_month.month,
time_by_month.quarter,
products.category_description
FROM product_sales
JOIN products ON product_sales.product_id = products.product_id
JOIN time_by_month ON product_sales.month_id = time_by_month.month_id;
View:
6
How much of each product category did a selected customer buy?
Query:
SELECT customer_sales.product_id,
customer_sales.quantity,
products.category_description,
customers.customer_name
FROM customer_sales
JOIN customers ON customer_sales.customer_id = customers.customer_id
JOIN products ON customer_sales.product_id = products.product_id;
View:
How much are the sales reps selling? To whom are they selling?
Query:
SELECT DISTINCT sales_reps.manager_last_name,
sales_reps.manager_first_name,
sales_reps.sales_rep_last_name,
sales_reps.sales_rep_first_name,
customer_sales.product_id,
customer_sales.quantity,
products.product_description,
customers.customer_name
FROM customer_sales
JOIN customers ON customer_sales.customer_id = customers.customer_id
JOIN products ON customer_sales.product_id = products.product_id
JOIN sales_reps ON customer_sales.sales_reps_id = sales_reps.sales_reps_id
JOIN sales_reps alias_ppa_1556729891 ON customer_sales.manager_rep_id =
sales_reps.manager_rep_id;
View:
7
Which products or product categories are they selling?
Query:
SELECT DISTINCT sales_reps.sales_rep_last_name,
sales_reps.sales_rep_first_name,
customer_sales.product_id,
customer_sales.quantity,
products.category_description,
customers.customer_name
FROM customer_sales
JOIN customers ON customer_sales.customer_id = customers.customer_id
JOIN products ON customer_sales.product_id = products.product_id
JOIN sales_reps ON customer_sales.sales_reps_id = sales_reps.sales_reps_id
JOIN sales_reps alias_ppa_1556730192 ON customer_sales.manager_rep_id =
sales_reps.manager_rep_id;
View:
When were sales the best? When were sales the worst?
Query:
SELECT time_by_day.fiscal_year,
count(time_by_day.fiscal_year) AS count
FROM time_by_day
GROUP BY time_by_day.fiscal_year;
View:
During those times who was buying and who was making the sale?
Query:
SELECT DISTINCT sales_reps.manager_last_name,
sales_reps.manager_first_name,
sales_reps.sales_rep_last_name,
sales_reps.sales_rep_first_name,
customer_sales.product_id,
customer_sales.quantity,
products.product_description,
customers.customer_name
8
FROM customer_sales
JOIN customers ON customer_sales.customer_id = customers.customer_id
JOIN products ON customer_sales.product_id = products.product_id
JOIN sales_reps ON customer_sales.sales_reps_id = sales_reps.sales_reps_id
JOIN sales_reps alias_ppa_1556729891 ON customer_sales.manager_rep_id =
sales_reps.manager_rep_id;
View:
What was the sales revenue from a specific product over the last 12 months?
Query:
SELECT time_by_day.fiscal_year,
time_by_day.month,
customer_sales.gross_sales,
customer_sales.day_id,
products.product_description
FROM customer_sales
JOIN time_by_day ON customer_sales.day_id = time_by_day.day_id
JOIN products ON customer_sales.product_id = products.product_id
WHERE time_by_day.fiscal_year >= '2018'::numeric OR time_by_day.month >=
'4'::smallint;
View:
9
What was the highest volume of a product for a specific month?
Query:
SELECT product_sales.product_id,
product_sales.quantity,
time_by_month.fiscal_year,
time_by_month.month,
products.product_description
FROM product_sales
JOIN products ON product_sales.product_id = products.product_id
JOIN time_by_month ON product_sales.month_id = time_by_month.month_id
WHERE product_sales.quantity = 4::numeric;
View:
Within that product, which geographic region had the greatest revenue?
Query:
SELECT product_sales.product_id,
product_sales.gross_sales,
10
geographic_boundaries.state_name,
geographic_boundaries.city_name,
products.product_description
FROM product_sales
JOIN products ON product_sales.product_id = products.product_id
JOIN geographic_boundaries ON product_sales.geo_id = geographic_boundaries.geo_id
WHERE geographic_boundaries.city_name::text = 'Surabaya'::text;
View:
What was the profitability for each product or product category in a certain country for
specific year?
Query:
SELECT products.product_id,
products.product_description,
product_sales.gross_sales - product_sales.product_cost AS profit,
time_by_month.fiscal_year,
geographic_boundaries.country_name
FROM products
JOIN product_sales ON products.product_id = product_sales.product_id
JOIN time_by_month ON product_sales.month_id = time_by_month.month_id
JOIN geographic_boundaries ON product_sales.geo_id = geographic_boundaries.geo_id;
View:
Which country has generated the greatest average annual revenue by product?
Query:
SELECT geographic_boundaries.country_name,
sum(product_sales.gross_sales) AS total_revenue,
time_by_month.fiscal_year
FROM geographic_boundaries
JOIN product_sales ON geographic_boundaries.geo_id = product_sales.geo_id
JOIN time_by_month ON product_sales.month_id = time_by_month.month_id
GROUP BY geographic_boundaries.country_name, time_by_month.fiscal_year;
View:
11
What was the sales volume for a specific sales rep over the last 12 months?
Query:
SELECT
sales_reps.sales_rep_first_name,
sales_reps.sales_rep_last_name,
SUM(customer_invoices.gross_sales) as sales_volume
FROM customer_invoices
JOIN sales_reps ON customer_invoices.sales_reps_id = sales_reps.sales_reps_id
JOIN time_by_day ON customer_invoices.day_id = time_by_day.day_id
WHERE time_by_day.fiscal_year >= 2018 AND sales_reps.sales_reps_id = 1
GROUP BY sales_reps. sales_rep_last_name, sales_reps.sales_rep_first_name
View:
Which customer bought the highest volume through a particular sales rep for a specific
month?
Query:
SELECT
customers.customer_name,
SUM(customer_invoices.gross_sales) as sales_volume,
time_by_day. Month,
sales_reps.sales_rep_first_name,
sales_reps.sales_rep_last_name
FROM customer_invoices
JOIN sales_reps ON customer_invoices.sales_reps_id = sales_reps.sales_reps_id
JOIN customers ON customers.customer_id = customer_invoices.customer_id
JOIN time_by_day ON customer_invoices.day_id = time_by_day.day_id
WHERE time_by_day. month = 12 AND sales_reps.sales_reps_id = 5
GROUP BY customers.customer_name, time_by_day. Month,
sales_reps.sales_rep_first_name, sales_reps.sales_rep_last_name
View:
12
View:
How much does each sales rep sell across each of his or her assigned states?
Query:
SELECT sales_reps.sales_rep_first_name,
sales_reps.sales_rep_last_name,
SUM(customer_invoices.gross_sales) as sales_volume,
addresses.city_name
FROM customer_invoices
JOIN addresses ON addresses.address_id = customer_invoices.address_id
JOIN sales_reps ON customer_invoices.sales_reps_id = sales_reps.sales_reps_id
GROUP BY addresses.city_name, sales_reps.sales_rep_first_name,
sales_reps.sales_rep_last_name
View:
Within each state, which city had the greatest volume for a sales rep?
Query:
SELECT addresses.country_name,
addresses.city_name,
sales_reps.sales_rep_first_name,
sales_reps.sales_rep_last_name,
customer_invoices.gross_sales as sales_volume
FROM customer_invoices
JOIN addresses ON addresses.address_id = customer_invoices.address_id
JOIN sales_reps ON customer_invoices.sales_reps_id = sales_reps.sales_reps_id
WHERE sales_reps.sales_reps_id = 5
ORDER BY sales_volume DESC
View:
13