




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





-- create Sales database------ create database Sales
------Insert data into table: Staff----------- insert into Staff(staffID, staffName, staffPhone, staffAddress) values('01','Hung','11111111','10 Le Duan'); insert into Staff(staffID, staffName, staffPhone, staffAddress) values('02','Lan','22222222','20 Nguyen Thi Minh Khai'); insert into Staff(staffID, staffName, staffPhone, staffAddress) values('03','Ngoc','33333333','100 Le Loi'); insert into Staff(staffID, staffName, staffPhone, staffAddress) values('04','Hoang','44444444','15 Hai Ba Trung'); go ------Insert data into table: Customer----------- insert into Customer(customerID,customerName,customerPhone,customerAddress) values('01', 'Quang Minh', '987654321','3 Le Loi'); insert into Customer(customerID,customerName,customerPhone,customerAddress) values('02', 'Quang Teo', '123456789','1 Le Lai'); insert into Customer(customerID,customerName,customerPhone,customerAddress) values('03', 'Minh Beo', '456789123','3 Nam Ky Khoi Nghia'); go ------Insert data into table: Product----------- insert into Product(productID, productName, Unit, Price) values('LAP01','Laptop Dell','piece', 500 ); insert into Product(productID, productName, Unit, Price) values('LAP02','Laptop Lenovo','piece', 400 ); insert into Product(productID, productName, Unit, Price) values('IP01','Ipad Apple x','piece', 300 ); insert into Product(productID, productName, Unit, Price) values('IP02','Ipad Samsung','piece', 200 ); go ------Insert data into table: Bill----------- insert into Bill(billID, billDate, staffID, customerID) values ('111', '05/04/2020','01','02'); 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 ------Insert data into table: BillDetail----------- insert into BillDetail(billID,productID,quantity) values('111','LAP01', 5 ); 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)
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;
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 and P.Price * BD.quantity > = 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;
-------------------Statatics by Customer------------------------ select C.customerID, C.customerName, SUM(BD.quantity * P.Price) as Total from Customer C, Bill B, BillDetail BD, Product P where C.customerID = B.customerID
and B.billID = BD.billID and Bd.productID = P.productID group by C.customerID, C.customerName;
-------------------Statatics by Products------------------------ select P.productID,P.productName, Sum (BD.quantity) as Quantity, Sum(BD.quantity * P.Price) as Revenue from BillDetail BD, Product P where Bd.productID = P.productID group by P.productID,P.productName go