1. University of New York, Tirana
M.Sc. in Computer Science
Advanced DatabaseConcepts
Host:
Department of Computer Science
School of Computing and Mathematical Sciences
University ofGreenwich
Partner:
University of New York in Tirana
Student: Ester Daci
3. Abstract
According to changes that are happening in technology and business nowadays, even Airlines
Companies have to survive in this current competitive environment. Their customer data has
the potential to provide competitive advantage to these organizations.
One of the solutions to do it is by building a data warehouse, which are able to provide any
kind of information to the management level. This will not help the management of
organisations to make strategic decisions, but also will help the company to position in a good
place in the market.
This project is about building a simple data warehouse (data mart) for an Airline Company.
Initially are defined business requirements and is created a conceptual design of the source
databases. This includes collecting information about databases that are going to be included.
Next step is to create tables, relationships and do normalization of the tables.
The last one includes queries for populating and updating the database, and some procedures
to perform all the necessary actions.
4. Introduction
A data warehouse is a database designed to enable business intelligence activities: it exists to
help users understand and enhance their organization's performance. A data mart serves the
same role as a data warehouse, but it is intentionally limited in scope. It may serve one
particular department or line of business. The advantage of a data mart versus a data warehouse
is that it can be created much faster due to its limited coverage. (oracle.com, n.d.)
Figure.1. Architecture of Data Warehouse
As it is already introduced, in this project we are going to show the steps about building a data
mart for an Airline Company.
Below are shown the tables we are going to use as source in order to implement a data
warehouse in 3rd
normal form.
5. Figure.2.Tables that represent databases
Two of the biggest databases that the Airline Company has, are Agent_ Detail (AD), in which
is included data about distribution of agents in specific Agencies and Ticket_ Order_ Detail
(TOD). The Agent table contains attributes like Agent_ id, Agency_ id, Agent_ name and
Agent_ surname. The PRIMARY KEY of this table is Agent_ id. The Agency table contains
these attributes: Agency_ id, which is PRIMARY KEY, City, and No_ of_ Agent that a certain
agency has. These two tables are related together through Agency_ id which is a FOREGIN
KEY in Agent Table.
Ticket_ Order_ Detail (TOD) database includes tables like Ticket, Booking Details and
Customer. Ticket table is connected with Booking Detail table, through ticket_ id(PRIMARY
KEY in Ticket table and FOREGIN KEY in Booking Detail). The Agent table is linked with
Ticket table via agent_ id which is a FOREIGN KEY in Ticket table. We have also the
Customer table, which has customer_ id (PRIMARY KEY), agent_ id, customer_ name,
customer_ surname, phone number and age. Agent table is linked with Customer table via
Agent_ id which is a FOREIGN KEY in Customer table.
Now, let’s see for each database, what information includes each table and also analyse this
information. The first database as we said is Agent _Detail (AD). This database includes two
tables: Agent and Agency. The Agent table contains personal information, like agent’s name,
agent’s surname and of course the agency’s id about each agent that works in this Airline
Company. This is one of the most important information needed in building the data
warehouse, because this table gives us the possibility to input the data about agents and then
analyse some reports like the total sales of ticket per agent (based on relationship with other
tables as well). The reports generated will be used by managers of Airline Company for the
bonus schema of their employees based on total sales/agent. Knowing the fact that Agent’s
table include also Agency’s ID as FOREIGN KEY, from this table we can also distinguish the
sales per each agency.
The second table of the first database (AD) is Agency. This table contains attributes like
Agency _ID, City (where a specific agency is located) and number of employees (agents) that
each agency has. In relation with other tables, from this table we can extract necessary
information about total sales for example or time when the most of the tickets are sold. By
6. owning the reports mentioned, the managers and other departments can make better decisions,
for example the Department of Marketing can make promotions in ticket’s price during the
periods that the sales are increasing. The association between Agent’s table and Agency’s table
will always be one to many, so there are many agents who works in one agency.
Now, let’s analyse the second database Ticket _Order _Detail (TOD) and what information we
can extract by using the data of this database.
Ticket _Order _Detail database include tables like Ticket, Booking _Details and Customer.
The Ticket’s table as we said contains attribute likeTicket_ ID (PRIMARY KEY), Agent_ ID
(FOREIGN KEY), Customer_ ID (FOREIGN KEY), Price and Ticket_ Type (General
admission or VIP).
This table gives the company the necessary information in generating different reports. One
example of the report generated may be “How many customers have bought the VIP ticket” or
“How is the price changed in different periods of time for one special ticket_ type”. The last
two examples of reports and all the others are used by managers, analysts, marketing to enhance
their decision-making activities in order to improve business processes and build a competitive
advantage.
The second table is Booking_ Detail. The attributes included are Booking_ ID (PRIMARY
KEY), Ticket_ ID (FOREIGN KEY), Agent_ ID (FOREIGN KEY), Origin_ Country,
Destination _Country.
The examples of reports extract from this table may include “How many tickets have sold an
agent” or “Which is the most preferred destination country”.
The last table is Customer. This table include a general information about the clients of the
Airline Company. The attributes of Customer’s table are Customer_ ID, Agent_ ID, Customer_
name, customer_ surname, phone number and age. This type of information gives the company
the possibility to classify and analyse their customer. By generating different reports for
example “What is the average age of the customers that have ordered a VIP ticket” or “How
many customers have selected a certain destination country”.
Ticket table and Booking_ Detail table are associated with a relationship one to one with each
other. Customer Table is associated with Agent Table in AD database, with a relationship many
to many in that sense that one agent can serve to many clients, but even one client can be served
by many agents. So one client can order a ticket in different agency.
In the next sections, there is Entity Relationship Schema of Airline Company database in 3rd
normal form, also the star schema that introduces all the dimensions that are going to be taken
in consideration in this data modelling for the data mart of an Airline Comany.
7. Normalization
Database normalization is a technique of organizing the data in the database. Normalization is
a formal approach that applies a set of rules to associate attributes with entities. Normalization
is used when designing a database. (datanamic.com, n.d.)
Normalization is a data design process that has a high level goal of keeping each fact in just
one place to avoid data redundancy and insert, update, and delete anomalies. (oracle.com, n.d.)
Data model after Normalization:
Figure.3.Entity Relationship Schema
8. Star Schema and introduction of dimensions
The term star schema is a way of referring to a "dimensional modeling" approach to defining
your data model. Most descriptions of dimensional modeling use terminology drawn from the
work of Ralph Kimball, the pioneering consultant and writer in this field. Dimensional
modeling creates multiple star schemas, each based on a business process such as sales or
marketing. Star schemas divide data into facts and dimensions. Facts are the measurements of
some event such as a sale and are typically numbers. Dimensions are the categories you use to
identify facts, such as date, location, and product. (oracle.com, n.d.)
In the figure below there is the star schema of our database:
Figure.4: Star Schema
In our example there are 3 dimensions: Customer, Agent and Time Dimension.
Customer describes each customer based on their attributes identified by customer_ ID.
Agent describes each agent of this company identified by agent_ ID.
Time is the time of the flights.
The fact refers to every dimension. The association between the fact and the dimension is
always one to any, which means each fact is associated with exactly one unit of the single
dimension, and each unit of the dimension can be associated with any number of facts
(including 0). (Gornik, n.d.)
The dimension Agent will have three levels and one hierarchy:
Total
Agency
Agent
9. The attributes for agent dimension are:
agent fullname(firstname+lastname)
agentid
sourceid
Also, the dimension Customer will have three levels and one hierarchy:
Total
Age
Customer
The attributes for agency dimension:
agencyid
sourceid
The dimension Time will have three levels and one hierarchy:
Total
Year
Month
Attributes for the year:
Year
Attributes for the month:
Month name
Description
Quarter
Measures that going to be part are:
Total amount
Number of tickets sold
10. Overview ofQuery
In the first chapter we describe both the physical design and logical design of our data
warehouse.
In this chapter we are going to describe and show all the query needed to perform different
actions until we will implement the whole data warehouse for our Airline Company.
CREATE USERS…
CREATE TABLES…
SELECT…
INSERT… etc.
Queries for creating tables of our first database AD.
First of all we are going to create a user named ad. The commands used in CMD are:
SQL> CREATE USER ad IDENTIFIED BY ad;
User created.
SQL> GRANT Create Session TO ad;
Then, we create a new connection, and after this we start by creating tables:
Queries used for this are:
CREATE TABLE ad.Agency
( AgencyId number NOT NULL PRIMARY KEY, -- primary key column
City varchar2(50) NOT NULL,
NoOfAgents number NOT NULL
);
For populating the Agency table write the INSERT statement. For example:
INSERT INTO ad.Agency (AgencyId, City, NoOfAgents)
VALUES (1,'Tirana', 3);
11. The result after SELECT * from ad.Agency; is:
The second table of this database is Agent:
CREATE TABLE ad.Agent
(
AgentId number NOT NULL PRIMARY KEY, -- primary key column
AgencyId number NOT NULL,
AgentName varchar2(50) NOT NULL,
AgentSurname varchar2(50) NOT NULL,
CONSTRAINT FK_AgentWorks
FOREIGN KEY (AgencyId ) REFERENCES ad.Agency(AgencyId));
The first instance:
INSERT INTO ad.Agent (AgentId, AgencyId, AgentName, AgentSurname)
VALUES (1, 1,'John', 'Miller');
INSERT INTO ad.Agent (AgentId, AgencyId, AgentName, AgentSurname)
VALUES (2, 1,'Keith','Armstrong');
INSERT INTO ad.Agent (AgentId, AgencyId, AgentName, AgentSurname)
VALUES (3, 1,'Donna','Anderson');
INSERT INTO ad.Agent (AgentId, AgencyId, AgentName, AgentSurname)
VALUES (4, 2,'Janet','Bell');
INSERT INTO ad.Agent (AgentId, AgencyId, AgentName, AgentSurname)
12. VALUES (5, 2,'Rose','Saunders');
INSERT INTO ad.Agent (AgentId, AgencyId, AgentName, AgentSurname)
VALUES (6, 2,'Scott','Simpson');
INSERT INTO ad.Agent (AgentId, AgencyId, AgentName, AgentSurname)
VALUES (7, 3,'Steve','Thompson');
INSERT INTO ad.Agent (AgentId, AgencyId, AgentName, AgentSurname)
VALUES (8, 3,'Sam','White');
INSERT INTO ad.Agent (AgentId, AgencyId, AgentName, AgentSurname)
VALUES (9, 3,'Sam','White');
INSERT INTO ad.Agent (AgentId, AgencyId, AgentName, AgentSurname)
VALUES (10, 4,'Maria','Adams');
INSERT INTO ad.Agent (AgentId, AgencyId, AgentName, AgentSurname)
VALUES (11, 4,'Lili','Allen');
The next step is creating the other user TOD, that is going to use as a source database too.
create user tod identified by tod;
grant create session to tod;
grant resource to tod;
alter user tod default role resource;
13. Queries for creating tables of our first database TOD.
After this, just like we did for the first database, we now can create the third tables of the second
database.
CREATE TABLE tod.customer
(
CustomerId number NOT NULL PRIMARY KEY, -- primary key column
agencyid number NOT NULL,
CustomerName varchar2(50) NOT NULL,
CustomerSurbame varchar2(50) NOT NULL,
Age number NOT NULL,
PhoneNumber number NOT NULL);
CREATE TABLE tod.BookingDetails
(
BookingId number NOT NULL PRIMARY KEY, -- primary key column
TicketId number NOT NULL,
AgentId number NOT NULL,
OriginCountry varchar2(50) NOT NULL,
DestinationCountry varchar2(50) NOT NULL,
CONSTRAINT FK_Booking_Ticket
FOREIGN KEY (TicketId) REFERENCES tod.Ticket(TicketId));
14. CREATE TABLE tod.Ticket
(
TicketId number NOT NULL PRIMARY KEY, -- primary key column
AgentId number NOT NULL,
CustomerId number NOT NULL,
Price number NOT NULL,
TicketType varchar2(50) NOT NULL,
CONSTRAINT FK_Cust_Ticket
FOREIGN KEY (CustomerId) REFERENCES tod.Customer(CustomerId)
);
After creating these tables, it should be displayed the below result:
15. And the INSERT statement for the tables BOOKING DETAILS, TICKET and CUSTOMER
is as follows:
INSERT INTO tod.customer VALUES (101, 1,'Dave','Smith', 24, 35569878);
INSERT INTO tod.customer VALUES (102, 1,'Ivan','Brown', 30, 35569585);
INSERT INTO tod.customer VALUES (103, 2,'Ramon','King', 23, 35421412);
INSERT INTO tod.customer VALUES (104, 2,'Ester','Moore', 44, 3521352);
INSERT INTO tod.customer VALUES (105, 4,'Jorge','Lopez', 45, 35252512);
INSERT INTO tod.customer VALUES (106, 3,'Roberto','Miller', 35, 3522511);
INSERT INTO tod.customer VALUES (107, 5,'Nathaniel','Wilson', 55, 35263611);
INSERT INTO tod.customer VALUES (108, 6,'Claude','Hill', 51, 352652511);
INSERT INTO tod.customer VALUES (109, 6,'Ethan','Taylor', 31, 352652513);
INSERT INTO tod.customer VALUES (110, 7,'Lewis','Jackson', 31, 3526587813);
INSERT INTO tod.customer VALUES (111, 7,'Glen','Nelson', 29, 3526587813);
INSERT INTO tod.customer VALUES (112, 8,'Joshua','Thomas',59, 38887813);
INSERT INTO tod.customer VALUES (113, 9,'Peter','Harris', 39, 38855513);
INSERT INTO tod.customer VALUES (114, 10,'Shane','Cooper', 20, 388544443);
INSERT INTO tod.customer VALUES (115, 11,'Aaron','Mitchell', 35, 35555443);
COMMIT;
Write: select * from tod.customer;
16. The population of the second table:
INSERT INTO tod.Ticket VALUES (1, 1, 101, 35,'General admission');
INSERT INTO tod.Ticket VALUES (2, 1, 102, 55,'General admission');
INSERT INTO tod.Ticket VALUES (3, 1, 101, 105,'VIP');
INSERT INTO tod.Ticket VALUES (4, 2, 103, 111,'General admission');
INSERT INTO tod.Ticket VALUES (5, 2, 101, 222,'VIP');
INSERT INTO tod.Ticket VALUES (6, 3, 104, 202,'General admission');
INSERT INTO tod.Ticket VALUES (7, 4, 105, 41,'General admission');
INSERT INTO tod.Ticket VALUES (8, 6, 106, 102,'General admission');
INSERT INTO tod.Ticket VALUES (9, 7, 106, 23,'General admission');
INSERT INTO tod.Ticket VALUES (10, 7, 106, 255,'VIP');
INSERT INTO tod.Ticket VALUES (11, 8, 107, 95,'General admission');
INSERT INTO tod.Ticket VALUES (12, 8, 101, 105,'General admission');
INSERT INTO tod.Ticket VALUES (13, 9, 108, 75,'General admission');
INSERT INTO tod.Ticket VALUES (14, 9, 109, 35,'General admission');
INSERT INTO tod.Ticket VALUES (15, 10, 111, 35,'General admission');
INSERT INTO tod.Ticket VALUES (16, 11, 110, 55,'General admission');
INSERT INTO tod.Ticket VALUES (17, 11, 114, 102,'General admission');
INSERT INTO tod.Ticket VALUES (18, 11, 115, 52,'General admission');
INSERT INTO tod.Ticket VALUES (19, 9, 113, 111,'VIP');
17. INSERT INTO tod.Ticket VALUES (20, 11, 112, 101,'General admission');
COMMIT;
Write: Select * from tod.Ticket;
18. The population of the third table:
INSERT INTO tod.BookingDetails VALUES (10, 1, 1,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (11, 2, 2,'Italy','Albania');
INSERT INTO tod.BookingDetails VALUES (12, 3, 3,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (13, 4, 4,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (14, 5, 5,'Italy','Albania');
INSERT INTO tod.BookingDetails VALUES (15, 6, 6,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (16, 7, 7,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (17, 7, 7,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (18, 8, 8,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (19, 9, 9,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (20, 10, 10,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (21, 11, 11,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (22, 12, 1,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (23, 13, 2,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (24, 14, 3,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (26, 15, 4,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (27, 16, 5,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (28, 17, 6,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (29, 18, 7,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (29, 18, 7,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (29, 19, 8,'Albania','Italy');
INSERT INTO tod.BookingDetails VALUES (30, 20, 9,'Italy','Albania');
COMMIT;
19. Write: select * from tod.BookingDetails;
Once we have created the tables as sysdba, we create user dataw, in order to use as our data
warehouse.
create user dataw identified by dataw
default tablespace USERS
temporary tablespace USERS
account unlock;
grant create session to dataw;
grant resource to dataw;
alter user dataw default role resource;
20. As we did for the first databases, as user dataw we have to create tables based on dimensions
we have determined. Two tables we are going to use are table agent and table customer, and
fact_table.
CREATE TABLE agent(
id number(6,0) PRIMARY KEY,
id_total number(6,0),
total varchar2(30),
idagency number (6,0),
agencySourceId number (6,0),
agentid number (6,0),
fullname varchar2(46),
agent_source_id number (6,0)
)
CREATE TABLE customer(
id number(6,0) PRIMARY KEY,
id_total number(6,0),
total varchar2(30),
avg_age number (6,0),
custid number (6,0),
cust_fullname varchar2(46),
cust_source_id number (6,0)
)
select * from dataw.agent;
select * from dataw.customer;
21. Fact table:
CREATE TABLE fact_table(
time_id number(6, 0),
agent_id number(6, 0),
customer_id number(6,0),
amount NUMBER(8,2),
no_tickets number(6,0),
CONSTRAINT "agent_id_FK" FOREIGN KEY (agent_id)
REFERENCES dataw.agent(id),
CONSTRAINT "customer_id_FK" FOREIGN KEY (customer_id)
REFERENCES dataw.customer(id),
CONSTRAINT "pk" PRIMARY KEY (agent_id, customer_id,time_id));
Write: select * from dataw.fact_table; we can see all the attributes added in fact_table:
22. In order to have access in two source databases, we should grant access to the target schema as
sysdba:
grant select on ad.agent to dataw;
grant select on ad.agency to dataw;
grant select on tod.BookingDetails to dataw;
grant select on tod.customer to dataw;
grant select on tod.ticket to dataw;
The CREATE SEQUENCE statement allows you to create a new sequence in the database.
Create the sequence for the dimension agent.
create sequence seq_agent
start with 1
increment by 1;
Create the sequence for the dimension customer.
create sequence seq_cust
start with 1
increment by 1;
Next step is to fill the two tables we created on dataw, with values:
insert into agent (id, total) values ( seq_agent.nextval,'All agents');
update agent set id_total=id;
23. Write: select * from dataw.agent;
Once we have created the two tables in dataw schema, now we have to insert the values. The
values will be taken from our two source databases AD and TOD. We have determined the
Agent dimension with three levels: Total, Agency and Agent.
The population of data warehouse will become by filling one by one the dimensions:
1) Fill the agency level
As sysdba grant access to the target schema to select the source tables:
grant select on ad.agency to dataw;
Now we can write INSERT statement:
insert into agent(id,id_total, total, agencySourceId )
select seq_agent.nextval,
a.id_total,
a.total,
AgencyId as agencySourceId
from ad.agency cross join agent a;
update agent set idagency=id where agencySourceId is not null;
Write: select * from dataw.agent;
24. 2) Fill the agent level:
insert into agent (id, id_total, total,idagency , agencySourceId , fullname,agent_source_id)
select seq_agent.nextval,
a.id_total,
a.total,
a.idagency,
a.agencySourceId,
source.AgentName || ' ' || source.AgentSurname as fullname,
source.AgentId as source_id
from ad.Agent source join agent a on source.AgencyId=a.agencySourceId;
3) Insert values in Customer Table
3.1) Fill the TOTAL level
insert into customer (id, total) values ( seq_cust.nextval,'All customers');
update customer set id_total=id;
Write: select * from customer;
25. In customer table, we are going to made a change. A new attribute age_source_id will be added,
by using ALTER statement:
ALTER TABLE customer
ADD age_source_id number;
3.2) Fill the age level:
insert into customer(id, id_total, total, avg_age, age_source_id)
select
seq_cust.nextval as id, c.id_total, c.total,source.age, source.customerid
from tod.customer source cross join customer c;
3.3) Fill the customer level:
insert into customer(id, id_total, total, avg_age, age_source_id,cust_fullname, cust_source_id)
select seq_cust.nextval as id,
target.id_total,
target.total,
target.avg_age,
target.age_source_id,
source.customername || ' '|| source.customersurbame as fullname,
source.CustomerId as cust_source_id
26. from tod.customer source join customer target on source.CustomerId =target.age_source_id;
update customer set custid =id where cust_source_id is not null;
27. The last dimension that is needed to take into consideration is TIME DIMENSION. Let’s start with
creation of tables one by one:
create table TIME(
id number(6,0) primary key,
id_total number(6,0),
total varchar2(20),
id_year number(6,0),
year number(4),
id_month number(6,0),
month number(2),
description varchar2(20),
quarter number(1)
)
As we did for the other tables, the next step is to create the time sequence:
create sequence time_seq
start with 1
increment by 1;
1) Fill the total level
insert into TIME (id,total) values (TIME_SEQ.nextval,'All years');
update time set id_total=id;
2) Create the procedure to insert records for the years
create or replace PROCEDURE add_years
( first_year number, second_year number )
IS
28. y number;
BEGIN
y:=first_year;
while (y <=second_year)
loop
insert into time (id,id_total, total, year)
select time_seq.nextval,id_total, total,y from time
where year is null;
y:=y+1;
end loop;
END add_years;
3) EXECUTE the procedure add_years
exec add_years(2001,2010);
update time set id_year=id where year is not null;
4) Insert the records for the months
insert into time(id, id_total, total, id_year, year,month, description, quarter )
select time_seq.nextval , t.id_total, t.total, t.id_year, t.year,
months.month, months.descr, months.quarter
from time t cross join
(
select 1 month, 'Jan' Descr, 1 Quarter from dual
union
select 2 month, 'Feb' Descr, 1 Quarter from dual
union
29. select 3 month, 'Mar' Descr, 1 Quarter from dual
union
select 4 month, 'Apr' Descr, 2 Quarter from dual
union
select 5 month, 'May' Descr, 2 Quarter from dual
union
select 6 month, 'Jun' Descr, 2 Quarter from dual
union
select 7 month, 'Jul' Descr, 3 Quarter from dual
union
select 8 month, 'Aug' Descr, 3 Quarter from dual
union
select 9 month, 'Sep' Descr, 3 Quarter from dual
union
select 10 month, 'Oct' Descr, 4 Quarter from dual
union
select 11 month, 'Nov' Descr, 4 Quarter from dual
union
select 12 month, 'Dec' Descr, 4 Quarter from dual
) months
where t.id_year is not null;
update time set id_month=id where month is not null;
30. Fact_Table is the last table, we are going to INSERT values. One last thing except dimensions
are measures Total amount and number of tickets sold. In order to determine time dimension,
it is needed to add another attribute ticket_date, in Ticket table, in the second database TOD.
alter table ticket add ticket_date number(10);
Let’s update the new column:
update tod.ticket set ticket_date = 10112019 where TicketId =1;
update tod.ticket set ticket_date = 10122019 where TicketId =2;
update tod.ticket set ticket_date = 11112019 where TicketId =3;
update tod.ticket set ticket_date = 12112019 where TicketId =4;
update tod.ticket set ticket_date = 13112019 where TicketId =5;
update tod.ticket set ticket_date = 14112019 where TicketId =6;
update tod.ticket set ticket_date = 15112019 where TicketId =7;
update tod.ticket set ticket_date = 16112019 where TicketId =8;
update tod.ticket set ticket_date = 17112019 where TicketId =9;
update tod.ticket set ticket_date = 21112019 where TicketId =10;
update tod.ticket set ticket_date = 22112019 where TicketId =11;
update tod.ticket set ticket_date = 23112019 where TicketId =12;
update tod.ticket set ticket_date = 24112019 where TicketId =13;
update tod.ticket set ticket_date = 24122019 where TicketId =14;
update tod.ticket set ticket_date = 25112019 where TicketId =15;
update tod.ticket set ticket_date = 26112019 where TicketId =16;
update tod.ticket set ticket_date = 27112019 where TicketId =17;
update tod.ticket set ticket_date = 28112019 where TicketId =18;
update tod.ticket set ticket_date = 29112019 where TicketId =19;
update tod.ticket set ticket_date = 30112019 where TicketId =20;
31. Now, we have to INSERT values in fact_table.
insert into fact_table (agent_id, customer_id,time_id, amount,no_tickets)
select t.id, a.id, c.id,
sum(source.price) as amount,
count(source.TicketId) as no_tickets
from
tod.ticket source join customer c on source.CustomerId=c.cust_source_id
join agent a on source.TicketId=a.AgentId
join time t on (to_char(ticket_date,'yyyy')=t.year
and to_char(ticket_date,'mm')=t.month)
group by t.id,a.id, c.id
order by t.id,a.id, c.id;
32. RAPORTS
Below are some raports based on information above that we inserted in our data warehouse user:
1)Suppose we want the amount based on price of ticket sold per each agent and per each agent we
need fullname and agent id. In dataw, write the below query:
select agent_id,fullname,amount form fact_table join agent on fact_table.agent_id=agent.agentid;
2)The second would be the number of tickets that each customer has bought in this company:
Select customer_id,no_tickets from fact_table join customer on
fact_table.customer_id=customer.custid;
3)All the tickets sold in December
Select no_ticket,time from fact_table where time between ‘01122019’ and ‘31122019’;
4)Average age of customers
Select custid,cust_fullname, sum(avg_age)/2 as ‘avarage age’ from customer;
5)Number of tickets sold per each agency.
Select id_agency,no_tickets from fact_table join agent on fact_table.agent_id=agent.agentid;
33. References
datanamic.com. (n.d.). https://www.datanamic.com/support/database-normalization.html.
Retrieved from https://www.datanamic.com/support/database-normalization.html.
Gornik, D. (n.d.). https://www.techwell.com/sites/default/files/articles/XUS2170853file1_0.pdf.
Retrieved from
https://www.techwell.com/sites/default/files/articles/XUS2170853file1_0.pdf.
oracle.com.(n.d.). https://docs.oracle.com/database/121/DWHSG/E41670-11.pdf.Retrievedfrom
https://docs.oracle.com/database/121/DWHSG/E41670-11.pdf:
https://docs.oracle.com/database/121/DWHSG/E41670-11.pdf