Lab1 De180456 DBI

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Lab 1: Chapter 01 and Chapter 02

for the contact relationship schema that manages the customer ordering system at Da Nang city. write
expressions of relational algebra to answer the following queries.

Customer(CustomerId, CustomerName, Birthday, Street, Award, District, PhoneNumber)

Discount(DiscountId, DiscountName, StartDate, EndDate, DiscountPercent)

Product(ProductId, ProductName, Prices, Unit, Quantity, Origin, DiscountId)

Order(OrderId, CustomerId, DateOrder, DateDeliver, Status, FeeShip,Description)

OrderDetails(OrderId, ProductId, QuantityOr)

Customer

CustomerId CustomerName Birthday Street Award District PhoneNumber


Cus_001 Nguyen Thanh 07/11/1988 15 Hoang Nam Hai Chau 0905446789
An Dieu Duong
Cus_002 Tran Bich Ngoc 19/07/1997 34 Cam Bac Hoa Cam Le 0987667032
8 Tho
Dong
Cus_003 Nguyen Thi 25/11/1996 67 Thanh Thanh Thanh 0910789098
Thanh Thuy Hoa Xuan Khe
Cus_004 Doan Phuoc 10/04/2001 30 Tran Quy Hoa Hoa 0236789032
Trung Cap Hai Vang
Cus_005 Nguyen Vu 21/21/2002 20 To Tam Hoa Lien 0890883921
Thanh Tien Khanh Chieu

Product

ProductId ProductName Prices (VND) Unit Origin Quantity DiscountId


P00001 Giuong thong 2008000 Cai Nhat 100
minh
P00002 Apple Airpod 4789000 Hop My 200
Pro 2 lightning
P00003 Dien Thoai 13990000 Cai Han 100
Samsung
Galaxy Z Flip 4
P00004 Keo Socola My 316000 Goi Viet Nam 1000
P00005 Bo Noi Inox 3 428000 Cai Han 1100
day Sunhouse

Discount

DiscountId DiscountName StartDate EndDate DiscountPercent


DC001 Quoc khanh 01/08/2022 02/09/2022 50%
DC002 Tet Duong Lich 25/12/2022 1/1/2023 20%
DC003 Quoc te phu nu 1/10/2022 20/10/2022 25%
DC004 Quoc khanh 01/08/2021 02/09/2021 50%
DC005 Tet Duong Lich 25/12/2021 1/1/2022 20%
DC006 Quoc te phu nu 1/10/2021 20/10/2021 25%
DC007 Quoc khanh 01/08/2023 02/09/2023 50%
DC008 Tet Duong Lich 25/12/2023 1/1/2024 20%
DC009 Quoc te phu nu 1/10/2023 20/10/2023 25%

Order

OrderId CustomerId DateOrder DateDeliver Status FeeShip Description


OD0001 Cus_001 10/12/202 15/12/2022 Da giao 15000 Hang de vo
2
OD0002 Cus_001 01/03/202 07/03/2022 Da giao 35000 Hang thao lap
2
OD0003 Cus_003 13/04/202 15/04/2021 Huy Don 40000
1
OD0004 Cus_005 18/12/202 18/12/2023 Da giao 15000
3
OD0005 Cus_005 15/11/202 30/11/2023 Huy Don 100000
3
OD0006 Cus_005 18/12/202 25/12/2023 Chua giao 45000
3

OrderDetails

OrderId ProductId QuantityOr


OD0001 P00001 1
OD0001 P00002 2
OD0002 P00001 1
OD0003 P00004 1
OD0003 P00001 3
OD0003 P00002 1
OD0004 P00004 6
OD0005 P00004 7
OD0006 P00001 1
OD0006 P00002 2
Write expressions of relational algebra to answer the following queries:

1. List Customers including Customer_name, Birthday with Birthday greater than 30/12/1995

Result:


(Customername , Birthday)
(
(σ Birthday ≥
30
12
/1995 ,Customers ) )
Customer_nam Birthday
e
Tran Bich Ngoc 19/07/1997
Nguyen Thi 25/11/1996
Thanh Thuy
Doan Phuoc 10/04/2001
Trung
Nguyen Vu 21/21/2002
Thanh Tien

2. List Product_name, Prices, Origin, Quantity of Products with Prices < 2,000,000 and Quantity >
100.

Result:
∏ (σ ( Prices< 2000000˄ Quantityt >100 , Product ) )
(Produc t name , Prices ,Origin ,Quantity )

Product_name Prices Origin Quantity


Binh Giu Nhiet 316000 Viet Nam 1000
Bo Noi Inox 3 day 428000 Han 1100
Sunhouse

3. List CustomerId, CustomerName, District, PhoneNumber of Customers who have ever


placed an order originating from "China" but have never placed an order originating
from "USA".

4. List the CustomerId, DateOrder that placed an order in 2022 if any

∏ (σ ( YEAR ( Orde r DateOrder )=2022 , Orders ) )


(CustomerId, DateOrder )

5. List ProductName of Products with Origin in both Japan and Korea


∏ (σ ( Origin¿' Japan' ˄Origin=' Korean ' , Products ))
(ProductName )
6. List the ProductName of all Products that have been ordered by Customers

∏ ¿ ¿)
(ProductName )

7. List the CustomerId of all Customers whose District is “Hai Chau” and have placed orders
in 2022 or Customers whose District is “Lien Chieu” who have placed orders in 2023

∏ ' ' ' '


(σ ( District ¿ HaiChau ˄¿YEAR ( Order s DateOrder )=202) ˅σ (District ¿ Lien Chie u ˄YEA
( CustomersID )
8. List ProductName of Products ordered by Customer but never successfully delivered.
∏ ' '
(σ (Orde r Status ≠ Da giao ˅ Orde r Status =NULL, Order ⋈ OrderDetail ⋈ Product ¿))¿
( ProductName )

9. List CustomerName of Customers who have made purchases in quantities > 5


∏ (σ (OrderDetail s QuatityOR > 5 ,Customer ⋈ Order ⋈ OrderDetails) ¿ ) ¿
( CustomerName )

10. List CustomerName of Customers who have placed orders 3 times or more
∏ ¿¿
( CustomerName )

-----------------------END---------------------------

You might also like