Consider the following schema: Customer (SSN: integer, cname:string, cgender: st
ID: 3559016 • Letter: C
Question
Consider the following schema:
Customer (SSN: integer, cname:string, cgender: string, ccity: string)
BuyVehicle (SSN: integer, vin:integer, price: real, byear: integer)
Vehicle (vin: integer, vmaker: string, vmodel: string, vyear: interger)
Suppose SSN is 6-digit integer and vin is a 5-digit integer. The key fields are
underlined, and the domain of each field is listed after the field name. Consider
the following queries.
1. Find the name of those customers who bought vehicles with price
greater than 30K.
2. Find the names of those customers who have bought at least one vehicle
made by Toyota, during the period from 2000 to 2006, whose price is
less than $20000.
3. Find the names of all customers who did not buy a vehicle in 2010.
4. Find SSN pairs of different customers who have bought vehicles with
same maker, model and year. You should avoid printing (SSN1, SSN2) if
(SSN2, SSN1) has been included.
5. Find the SSNs of those male customers who have bought ALL vehicles
made by Toyota.
You should do the following:
? Write queries for 1 through 5 in Relational Algebra and Tuple Relational
Calculus.
Explanation / Answer
1) select c.cname from customer c, buy_vehicle b where c.SSN=b.SSN and b.price>30000
2) select c.cname from customers c, buyvehicle b, vehicle v where c.SSN=b.SSSN, b.vin=v.vin, b.byear BETWEEN 2000 and 2006
3) select c.cname from customer c, buy_vehicle b where c.SSN=b.SSN where b.byear <> 2010
4) --
5) select b.SSN from buy_vehicle b, customer c, vehicle v where c.SSN=b.SSN, v.vehicle='toyota', c.cgender='male'
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.