Docsity

Homework 2 with 10 Problems - Database Systems | CS 480, Assignments of Deductive Database Systems

Toggle sidebar
bg1
CS480 - Database Systems
Spring 2009
Homework(2): SQL
Due on: 03/09/2009, Monday. Hardcopy in the class. Electronic
version turned in before 12:00pm
No late submission accepted.
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: integer)
Suppose SSN is a 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 names of those customers who bought vehicles in year 2001.
2. Find the names of those customers who have bought at least one vehicle made by
Honda.
3. Find the names of all customers who have NEVER bought a vehicle yet.
4. Find SSN pairs of different customers who have bought vehicles with same make,
model and made year. You should avoid printing (SSN1, SSN2) if (SSN2, SSN1) has
been included.
5. Find the SSNs of those female customers who have bought ALL vehicles made by
Nissan.
6. Find the makes and models of those vehicles such that every customer who bought
such vehicles paid at least $10.000 for them.
7. Find the make and model of the most popular vehicle. (The number of customers who
bought such vehicles, is the most.)
8. Find the names of all customers who paid a higher price for some vehicle than the
average price of the same vehicle (same make, same model and same made year) sold.
9. Find the vehicle with the highest price for each make.
10. Find the total price of all vehicles paid by each customer who has bought at least two
vehicles and group by the name of the customer.
You should do the following.
๎˜ Write queries (1) through (5) in Relational Algebra and Tuple Relational Calculus.
Submit hardcopy of answers in class as given above.
๎˜ Write queries (1) through (10) in SQL. Your answers must be correct for any
pf2

Partial preview of the text

Download Homework 2 with 10 Problems - Database Systems | CS 480 and more Assignments Deductive Database Systems in PDF only on Docsity!

CS480 - Database Systems

Spring 2009 Homework(2): SQL Due on: 03/09/2009, Monday. Hardcopy in the class. Electronic version turned in before 12:00pm No late submission accepted.

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: integer)

Suppose SSN is a 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 names of those customers who bought vehicles in year 2001.
  2. Find the names of those customers who have bought at least one vehicle made by Honda.
  3. Find the names of all customers who have NEVER bought a vehicle yet.
  4. Find SSN pairs of different customers who have bought vehicles with same make, model and made year. You should avoid printing (SSN1, SSN2) if (SSN2, SSN1) has been included.
  5. Find the SSNs of those female customers who have bought ALL vehicles made by Nissan.
  6. Find the makes and models of those vehicles such that every customer who bought such vehicles paid at least $10.000 for them.
  7. Find the make and model of the most popular vehicle. (The number of customers who bought such vehicles, is the most.)
  8. Find the names of all customers who paid a higher price for some vehicle than the average price of the same vehicle (same make, same model and same made year) sold.
  9. Find the vehicle with the highest price for each make.
  10. Find the total price of all vehicles paid by each customer who has bought at least two vehicles and group by the name of the customer.

You should do the following.  Write queries (1) through (5) in Relational Algebra and Tuple Relational Calculus. Submit hardcopy of answers in class as given above.  Write queries (1) through (10) in SQL. Your answers must be correct for any

valid state of any table. Submit your answers in hardcopy in class. Note: Your answers must be printed. Credits will be deducted if your answers are illegible.  You should also test your SQL queries on Oracle. You can find tips on "how to connect to and perform a query on Oracle" on the course webpage: http://www.cs.uic.edu/~i480/oracle.html Write all your SQL queries into a "yourloginname.sql" file. Please remember to substitute the "yourloginname" with your real login name and include the ";" after each query. Credits will be deducted if your SQL queries can not run on Oracle.  Turnin your .sql file from bert by using the following command: [bert]-> turnin -c cs480 -p sql yourloginname.sql