Vous êtes sur la page 1sur 5

question 1

1-a)

create table EMP_INFO


(
emp_id number,
name varchar(20),
age number,
address varchar(30),
dob date,
dt_of_join date,
salary number,
dept_no number
);

1-b)

insert into emp_info values(1,'paras',24,'bara bazar','02-10-1995','21-10-


2017',50000,2);

insert into emp_info values(2,'swapnil',21,'mp','04-03-1996','21-10-2017',50000,3);

insert into emp_info values(3,'kinshuk',25,'bara bazar','02-10-1992','21-10-


2017',50000,7);

insert into emp_info values(4,'sheenam',20,'najibabad','31-10-1996','21-10-


2017',50000,8);

insert into emp_info values(5,'tron',24,'bara bazar','02-09-1991','21-10-


2017',50000,4);
insert into emp_info values(5,'aman',25,'bara bazar','21-01-1992','21-10-
2017',100000,4);

1-c)

select sum(salary),dept_no from emp_info


group by dept_no
order by dept_no;

1-d)

create view custom as


select emp_id,dt_of_join,salary from emp_info;

select * from custom;

question 2

2-a)
create table TIME_DIM_Tb(time_key number primary key , day varchar(10),
day_of_the_week varchar(10), month varchar(10), quarter number, year number);

create table ITEM_DIM_Tb(item_key number primary key, item_name varchar(100), brand


varchar(20), type varchar(10), supplier_type varchar(10));

create table BRANCH_DIM_Tb(branch_key number primary key, branch_name varchar(50),


branch_type varchar(10));

create table LOCATION_DIM_Tb(location_key number primary key, street varchar(50),


city varchar(10), state varchar(10), country varchar(15));

create table SALES_FACT_Tb( time_key number references TIME_DIM_Tb(time_key),


item_key number references ITEM_DIM_Tb(item_key), branch_key number references
BRANCH_DIM_Tb(branch_key), location_key number references
LOCATION_DIM_Tb(location_key), rupees_sold number, units_sold number );

2-b)

insert into time_dim_tb


values(1,'Monday',1,'January',1,2001);
insert into time_dim_tb
values(2,'Tuesday',2,'February',2,2002);
insert into time_dim_tb
values(3,'Wednesday',3,'March',3,2003);
insert into time_dim_tb
values(4,'Thursday',4,'April',4,2004);
insert into time_dim_tb
values(5,'Friday',5,'May',1,2005);

select * from time_dim_tb;

insert into item_dim_tb


values(1,'item1','brand1','type1','supplier1');
insert into item_dim_tb
values(2,'item2','brand2','type2','supplier2');
insert into item_dim_tb
values(3,'item3','brand3','type3','supplier3');
insert into item_dim_tb
values(4,'item4','brand4','type4','supplier4');
insert into item_dim_tb
values(5,'item5','brand5','type5','supplier5');

select * from item_dim_tb;

insert into branch_dim_tb


values(1,'branch1','btype1');
insert into branch_dim_tb
values(2,'branch2','btype2');
insert into branch_dim_tb
values(3,'branch3','btype3');
insert into branch_dim_tb
values(4,'branch4','btype4');
insert into branch_dim_tb
values(5,'branch5','btype5');

select * from branch_dim_tb;

insert into location_dim_tb


values(2,'street2','city2','state2','country2');
insert into location_dim_tb
values(3,'street3','city3','state3','country3');
insert into location_dim_tb
values(4,'street4','city4','state4','country4');
insert into location_dim_tb
values(5,'street5','city5','state5','country5');

select * from location_dim_tb;

insert into sales_fact_tb


values(1,1,1,1,100,100);
insert into sales_fact_tb
values(2,2,2,2,200,200);
insert into sales_fact_tb
values(3,3,3,3,300,300);
insert into sales_fact_tb
values(4,4,4,4,400,400);
insert into sales_fact_tb
values(5,5,5,5,500,500);

select * from sales_fact_tb;

2-c)

select d.units_sold from sales_fact_tb d,item_dim_tb e,location_dim_tb


f,branch_dim_tb g
where d.item_key=e.item_key and d.location_key=f.location_key and
d.branch_key=g.branch_key and
e.item_name='item2' and g.branch_name='branch2' and f.city='city2';

2-d)

select sum(d.units_sold)as "total sale" from sales_fact_tb d,time_dim_tb e


where d.time_key=e.time_key and year=2003;

2-e)

select e.item_name,d.units_sold from sales_fact_tb d,item_dim_tb e,time_dim_tb f


where d.item_key=e.item_key and d.time_key=f.time_key and
f.quarter=1 and f.year=2001;

question 3

3-a)

create table PRODUCT_DIM_Tb(product_no number primary key,name


varchar(20),supplier_no number,supplier_name varchar(20));

create table SALESPERSON_DIM_Tb(salesperson_id number primary key, firstname


varchar(20), lastname varchar(20), address varchar(200), phone number);

create table CUSTOMER_DIM_Tb(customer_id number primary key,customer_name


varchar(20),billing_address varchar(200), billing_city varchar(20), billing_state
varchar(20), phone number);

create table ORDER_FACT_Tb(order_no number primary key,product_no number references


product_dim_tb(product_no),customer_id number references
customer_dim_tb(customer_id), salesperson_id number references
salesperson_dim_tb(salesperson_id), unit_price number, no_ordered number);

3-b)

insert into product_dim_tb


values(1,'product1',1,'supplier1');
insert into product_dim_tb
values(2,'product2',2,'supplier2');
insert into product_dim_tb
values(3,'product3',3,'supplier3');
insert into product_dim_tb
values(4,'product4',4,'supplier4');
insert into product_dim_tb
values(5,'product5',5,'supplier5');

insert into salesperson_dim_tb


values(1,'name1','last1','address1',900000);
insert into salesperson_dim_tb
values(2,'name2','last2','address2',800000);
insert into salesperson_dim_tb
values(3,'name3','last3','address3',700000);
insert into salesperson_dim_tb
values(4,'name4','last4','address4',600000);
insert into salesperson_dim_tb
values(5,'name5','last5','address5',500000);

insert into customer_dim_tb


values(1,'c1','baddress1','bcity1','bstate1',900000);
insert into customer_dim_tb
values(2,'c2','baddress2','bcity2','bstate2',800000);
insert into customer_dim_tb
values(3,'c3','baddress3','bcity3','bstate3',700000);
insert into customer_dim_tb
values(4,'c4','baddress4','bcity4','bstate4',600000);
insert into customer_dim_tb
values(5,'c5','baddress5','bcity5','bstate5',500000);

insert into order_fact_tb


values(1,1,1,1,200,5);
insert into order_fact_tb
values(2,2,2,2,300,6);
insert into order_fact_tb
values(3,3,3,3,400,7);
insert into order_fact_tb
values(4,4,4,4,500,8);
insert into order_fact_tb
values(5,5,5,5,600,9);

3-c)

select p.product_no,p.name from order_fact_tb o,product_dim_tb p,customer_dim_tb c


where o.product_no=p.product_no and o.customer_id=c.customer_id and
c.customer_id=1;

3-d)

select p.product_no,p.name from order_fact_tb o,product_dim_tb p


where o.product_no=p.product_no and o.no_ordered=(select max(no_ordered) from
order_fact_tb);

Vous aimerez peut-être aussi