Professional Documents
Culture Documents
vn
Part 1:
Students have to complete all following tasks:
1/ Logic database design: use Draw.io tool to create ERD (Entity relationship
diagram).
Table: Staff
Field name Data type Allow nulls Description
staffID varchar(6) X Staff code, primary key
staffName varchar(50) Full name of staff
staffPhone varchar(10) Phone number of staff
staffAddress varchar(50) Address information of staff
Table: Product
Field name Data type Allow nulls Description
prodcutID varchar(6) X Product code, primary key
productName varchar(50) Name of product
Unit varchar(10) X Unit of product
Price float Price of product
Table: Bill
Field name Data type Allow nulls Description
billID varchar(6) Bill code, primary key
billDate date X Bill date
customerID varchar(6) Customer code, foreign key
staffID varchar(6) Staff code, foreign key
Table: BillDeatail
Field name Data type Allow nulls Description
billID varchar(6) Bill code, foreign key
productID varchar(6) Product code, foreign key
quantity int X Quantity of bills
Table Customer
sonnv22@fpt.edu.vn
Table Product
Table Bill
insert into Bill(billID, billDate, staffID, customerID) values ('222',
'04/04/2020','01','01');
insert into Bill(billID, billDate, staffID, customerID) values ('333',
'03/04/2020','03','01');
go
Table BillDetail
insert into BillDetail(billID,productID,quantity) values('111','LAP02',10);
insert into BillDetail(billID,productID,quantity) values('111','IP01',20);
insert into BillDetail(billID,productID,quantity) values('222','IP01',5);
insert into BillDetail(billID,productID,quantity) values('222','IP02',3);
insert into BillDetail(billID,productID,quantity) values('222','LAP01',30);
insert into BillDetail(billID,productID,quantity) values('333','LAP01',1);
insert into BillDetail(billID,productID,quantity) values('333','LAP02',2);
insert into BillDetail(billID,productID,quantity) values('333','IP01',3);
insert into BillDetail(billID,productID,quantity) values('333','IP02',4);
go
Part 2:
1/ List all items with informations as following table:
sonnv22@fpt.edu.vn
------------------------------------------------------
select B.billID, B.billDate, C.customerName,S.staffName, P.productName,
P.Price, BD.quantity, P.Price * BD.quantity as Amount from Bill B,
Customer C, Staff S, Product P, BillDetail BD where B.billID =
BD.billID and B.customerID = C.customerID and B.staffID = S.staffID
and BD.productID = P.productID;
3/ List all items with informations as following table and Amount >= 1000:
-------------------Statatics by staff------------------------
select S.staffID,S.staffName, sum(BD.quantity * P.Price) as Revenue
from Staff S, Bill B, BillDetail BD, Product P where S.staffID =
B.staffID
and B.billID = BD.billID
and BD.productID = P.productID
group by S.staffID, S.staffName;