Relational Algebra Exercises

 

Product ( pid, name,  price, category, maker-cid)

Purchase (buyer-ssn,  seller-ssn,  store,  pid)

Company (cid, name, stock price, country)

Person(ssn, 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.

 

 

 

1. p ssn, name, phne-number, city (Person  ssn=buyer-ssn (p buyer-ssn (Purchase (s category=”telephony” Product))))

 

2. p name (Person  ssn=buyer-ssn (Purchase    ((p pid, maker-cid Product) maker-cid=cid (p cid (s country=”USA” Company)))))

 

3. p name ((Person  ssn=buyer-ssn (Purchase    ((p pid, maker-cid Product) maker-cid=cid (p cid (s country=”USA” Company)))))

 – (Person  ssn=buyer-ssn (Purchase    ((p pid, maker-cid Product) maker-cid=cid (p cid (s country=”France” Company))))))

 

4. p name ((s city=”Seattle” Person) ssn=buyer-ssn

(Purchase    ((p pid, maker-cid Product) maker-cid=cid (p cid (s country=”USA” Company)))))

 

5. p ssn, name, phne-number, city (Person  ssn=buyer-ssn (p buyer-ssn(Purchase seller-ssn=ssn (s name=”Joe” Person))))

p ssn, name, phne-number, city (Person  ssn=buyer-ssn (Purchase    ((p pid, maker-cid Product) maker-cid=cid (p cid (s stock-price>$50 Company)))))