80 likes | 246 Views
CSCI 4370/6370 Solutions to Test 1. (Dan Everett’s version). Database for Ch 1 and Ch 5 Q’s. Parcel (routingNum, from, fAddress, fPhone, to, tAddress, tPhone, sendDate, cost) Truck ( truckNum , driver, homeBase) Tracking ( routingNum, truckNum , pickUpDate, pLocation, dropOffDate, dLocation).
E N D
CSCI 4370/6370Solutions to Test 1 (Dan Everett’s version)
Database for Ch 1 and Ch 5 Q’s • Parcel (routingNum, from, fAddress, fPhone, to, tAddress, tPhone, sendDate, cost) • Truck (truckNum, driver, homeBase) • Tracking (routingNum, truckNum, pickUpDate, pLocation, dropOffDate, dLocation)
Ch. 1 Q: relational algebra SQL> select cost, sendDate from parcel where from=‘John Smith’ Result = πcost, sendDate (σfrom=‘John Smith’ Parcel)
Ch 3 Q: Relation terminology • “Draw a sample relation consisting of 5 3-tuples. Label the diagram to illustrate what a relation (in general) is built out of.”
Ch 5 Q: relational algebra queries • “Which truck does Pikup Andropov drive?” πtruckNum (σdriver=‘Pikup Andropov’ truck)
Ch 5 Q: relational algebra queries • “Track John Smith’s package sent 2005-06020 by listing all the drivers that have picked up his package and when they picked it up and dropped it off” πdriver, pickUpDate, dropOffDate ((σfrom=‘John Smith’ parcel)ΙXΙ(truck ΙXΙ tracking))
Explanation: (truck ΙXΙ tracking) = (truckNum, routingNum, driver, homeBase, pickUpDate, pLocation, dropOffDate, dLocation) parcel ΙXΙ(truck ΙXΙ tracking) = (truckNum, routingNum, from, fAddress, fPhone, to, tAddress, tPhone, sendDate, cost, driver, homeBase, pickUpDate, pLocation, dropOffDate, dLocation)
Ch 5 Q: relational algebra queries • “When was John Smith’s package delivered?” πdropOffDate (σ dLocation=tAddress andfrom=‘John Smith’ (parcel ΙXΙ(truck ΙXΙ tracking))) -or- πdropOffDate (σ dLocation=tAddress(σfrom=‘John Smith’ parcel) ΙXΙ(truck ΙXΙ tracking)))