0% found this document useful (0 votes)
7 views

Assignment Tt

Uploaded by

yosefmuluye42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Assignment Tt

Uploaded by

yosefmuluye42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1: Use the following Sailors and Reserves Relation to do the exercise

1. ∏sName,rating(σ rating>8(S2) )
2. ∏sName,rating(S2)
3. S1 S1.sid <R1.sid R1 R1
4. σ rating>8(S2)
5. S1 X R1 6. S1 n S2
7. 1.S1∏sName,rating(σ
U S2 rating>8(S2)
8. ) S1-S2
sname rating

Almaz 9

Zelalem 10

2. ∏sName,rating(S2)

sname rating

Almaz 9

Tigist 8

Worku 5

Zelalem 10
3. S1 S1.sid <R1.sid R1

sid sname rating Age sid bid day


22 Habtamu 7 45 58 103 11/12/96
31 Tigist 8 55 58 103 11/12/96

4. σ rating>8(S2)
sid sname rating age

28 Almaz 9 3

58 Zelalem 10 35

5. S1 X R1
sid sname rating Age sid bid day
22 Habtamu 7 45 22 101 10/10/96
22 Habtamu 7 45 58 103 11/12/96
31 Tigist 8 55 22 101 10/10/96
31 Tigist 8 55 58 103 11/12/96
58 Zalalem 10 35 22 101 10/10/96
58 Zalalem 10 35 58 103 11/12/96

6. S1 n S2
sid sname rating age

31 Tigist 8 55

58 Zelalem 10 35
7. S1 U S2

sid sname rating age

28 Almaz 9 3

31 Tigist 8 55

44 Worku 5 35

58 Zelalem 10 35

22 Habtamu 7 45

8. S1-S2

sid sname rating age

22 Habtamu 7 45

2: Write RA and SQL expressions


Product (pname, price, category, maker)
Purchase (buyer, seller, store, product)
Company (cname, stock price, country)
Person (per-name, phone number, city)
Ex #1: Find people who bought telephony products.
Ex #2: Find names of people who bought American products
Ex #3: Find names of people who bought American products and did
not buy French products
Ex #4: Find names of people who bought American products and they
live in Seattle.
Ex #5: Find people who bought stuff from Joe or bought products
from a company whose stock prices is more than $50.

Question 2 answer
1 . Select person. Per-name from person, purchase, product where person. per-name=purchase. Buyer
and product=product. name and product. Category="telephony".

 per-name, phone-number, city (Person⋈ per-


name=buyer ( buyer(Purchase ⋈ ( category=telephony Product))))

Select person.name

from person, purchase, product

Where person.name=bought and product=product.name and product.category=’ telephony’

2. Select person. Per-name from person, purchase, company where person.per-name=purchase.buyer


and company=company.cname and company. Country="usa"

name (Person⋈per-name =buyer(Purchase⋈ ((pname, maker Product) ⋈ maker=


namec (cname(country=USA Company)))))

Select * from product

Where product_name=”American”

3. Select person.per-name from person, purchase, company where person.per-name=purchase.buyer


and company=company.cname and company.country="usa" and person. City="Seattle".

name (Person⋈per-name =buyer(Purchase⋈((pname, maker Product) ⋈ maker=


namec (cname(country=USACompany)))))
name (Person⋈per-name =buyer(Purchase⋈ ((pname, maker Product) ⋈ maker=
namec (cname(country=French Company)))))

Select per_name from person

where product_name in(select product_name from product where product_name=’american’ or


product_name<> ‘French’);

4. Select person.per-name from person, purchase where person. Per-name=purchase.buyer and person.
per-name=purchase.seller.

name ((city=SeattlePerson) ⋈per-name=buyer


(Purchase⋈((pname, maker Product) ⋈ maker=cname (cname(country=USA
Company)))))
Select name from person, purchase where city=’seattle’ and product_name=’american’

5. Select person.per-name from person, purchase, company, product where product=product. name and
person. per-name=purchase.seller and purchase.seller="joe" or company.stock price>50.

 per-name, name, phone-number, city (Person⋈per-name =buyer (buyer(Purchase ⋈seller= per-

⋃per-name, name, phone-number, city (Person⋈per-name =buyer (Purchase⋈ ((pname, maker


name (name=JoePerson))))

Product) ⋈ maker=cname (cname(stock-price>$50 Company)))))


Select p_name from person, product,purchase,company

Where buyer =’joe’ and price>$50;

3, Write RA and SQL expressions


Queries
Q #1: List names of all branches in the bank.
Q #2: List names of customers together with their account number.
Q #3: Find all cities where at least one customers live.
Q #4: Find all cities with at least one branch.
Q #5: Find all cities where there is either a customer who lives or a
branch.
Q #6: Find all the cities that has a branch but not customers.
Q #7: Find the names of all branches with assets greater than 2500K.
Q #8: List the name and cities of all customers who has an account
with balance > 2000.
Q #9: List all the cities with some customers but without any bank
branches.
Q #10: Find the names of all customers who live in a city with no
bank branches.
Q #11: List the name and address of all customers who has an
account with balance > 2000.
Q #12: Find all customers who live in a city with no bank branch.
Q #13: Find all cities that have both the customers and bank branches.
Q #14: Find all the customers who has deposits in every branch of the
bank.
Q #15: Find the name and assets of all branches which have
customers living in Jasper.
Q #16: Find all customers who have both an account and a loan at the UofA.

Question 3 answer
1
SELECTb_name
FROM branch
Π b_name branch
2
SELECTcustomer.c_name, deposit.account_number
FROM customer, deposit
Π customer. c_name, deposit. Account number (customer × deposit)
3
SELECT city
FROM customer
WHERE (city ='jasper')
Π city
σ city = "jasper" customer
4
SELECT city
FROM branch
WHERE (city ='calgary')
Π city
σ city = "calgary" branch
5
SELECT city
FROM branch
Π city branch
6
SELECT city
FROM branch
WHERE (city ='Calgary')
Π city branch

7
SELECTb_name, assets
FROMbranch
WHERE assets > 2500;

8
SELECTcustomer.c_name, customer.city, deposit.account_number
FROM customer, deposit
WHERE (deposit.account_number> 2000)
Π customer. c_name, customer. city, deposit. Account number
σ deposit. Account number> 2000 (customer × deposit)
9
SELECT city
FROM customer
WHERE (city ='jasper')
Π city
σ city = "jasper" customer
10
SELECTc_name, city
FROM customer
WHERE (city ='jasper')

Π c_name, city
σ city = "jasper" customer
11
SELECTcustomer.c_name, branch.address, deposit.balance
FROM customer, branch, deposit
WHERE (deposit. Balance> 2000)
Π customer. c_name, branch. address, deposit. balance
σ deposit . Balance > 2000 (customer × branch × deposit)
12
SELECTc_name, street, city
FROM customer
WHERE (city ='jasper')
π c_name, street, city
σ city = "jasper" customer
13
SELECTcustomer.city,branch.cityAS Expr1
FROM customer, branch
π customer . city, branch . city → expr1 (customer × branch)
14
SELECTcustomer.c_name, customer.street,customer.city,deposit.b_name
FROM customer, deposit
π customer . c_name, customer. street, customer . city, deposit . b_name (customer × deposit)
15
SELECTbranch.b_name, branch.assets,customer.city
FROM branch, customer
WHERE (customer. city='jasper')
π branch . b_name, branch . Assets, customer. city
σ customer . city = "jasper" (branch × customer)

16
SELECTcustomer.c_name, customer.street, customer.city,deposit.b_name
FROM customer, deposit
WHERE (deposit.b_name='UofA')

Customer . c_name, customer . street, customer . city, deposit . B_name

σ deposit. b_name = "UofA" (customer × deposit)

You might also like