CPSC-110 Spring 2009
Lab 3
Thursday, February 5
Professor Heidi Ellis
Be sure that you hand in the print out of your work before leaving!!!
Objectives:
- Execute a series of complex queries against a database.
- Execute queries that use the built-in functions.
In this lab we will gain fluency using SQL queries. We will be investigating queries that use built-in functions, the in clause, the between clause and queries that use more than one condition in the where clause.
Pair Programming:
- Locate your partner and introduce yourself:
| Abby Alderman | Robert Perryman | |
| Richard Curtin | Preston Maddock | Alyssa Cockrell |
| Cory DiBenedetto | Ben McDaniel | |
| Briggs Elwell | Whitney Merrill | |
| Elise Galbo | Ryan Piacentini | |
| Brooke Haynes | Shanice Smith | |
| Nikki Lustig | Andrea Titone | |
| Brenna Fox | Matt Vibert | |
- Select one person's account in which to work.
- Select one person to start as "driver". Change drivers every five queries.
- Using KWrite (or another text editor), create a new file called lab3.txt. Put both team members' names in the document.
- Select the fuel_economy database and the fuel table.
- Take a minute to review the columns and rows in the table to familiarize yourself with the data. You need to understand the columns and their data in order to answer the queries.
- In the query area in the top, middle portion of the query browser, construct and execute an SQL query to answer the statements listed below. For each statement, write the SQL query that provides the correct response to the query in your lab3.txt file.
- Email the completed file to the partner in whose account you were not working so that they have a copy.
- Print the lab3.txt file and hand it in at the end of lab.
Queries:
- Show the class and displacement for all 8-cycle vehicles. Make sure that the result set contains no duplicates.
- Show the manufacturer and car line for all vehicles that get less than 20 MPG highway and have a displacement greater than 4. Label the column headings "Manufacturer" and "Line". Make sure that the result set contains no duplicates.
- Show the car line and combined miles per gallon for vehicles where the annual fuel cost is greater than $1500 or the combined miles per gallon is less than 25. Label the miles per gallon column "Combined Miles Per Gallon". Make sure that the result set contains no duplicates.
- Show the car lines for Toyotas that do not use premium fuel.
- Show the manufacturer, car line, and transmission for BMWs and Audis that get greater than 16 MPG city and Lexus' that get greater than 20 MPG city. Provide English-readable column names.
- Show the manufacturers of vehicles that have a displacement that is not between 2 and 3 and a rear wheel drive system. Make sure that the result set contains no duplicates.
- Show the manufacturers that start with "ch". Make sure not to include duplicate manufacturer names.
- Show the class and car line for all coupe vehicles that have an automatic transmission and get less then 25 MPG in the city.
- Show the car line and annual fuel cost for vehicles that use diesel fuel and vehicles that have a manual transmission and have an annual fuel cost less than $1100.
- Show the class and car line for automatic vehicles with an annual fuel cost of less than $1500 and manual vehicles with an annual fuel cost of less than $2000.
- Show the annual fuel cost and class for all vehicles that are any sort of a compact vehicle.
- Show an alphabetized list of manufacturers for all manufacturers of vehicles with automatic transmissions.
- Show the car line, manufacturer, and class of vehicles that have transmissions of type Auto(S6), Auto(L7), or Auto(S5). Use the "in" clause.
- Show the combined MPG and car line for all vehicles that are not Volvos, Mercedes, and Mazdas. Use the in operator. Make sure not to include duplicates in your result set.
- Show the car line, manufacturer, and class of vehicles that have average highway mileage between 20 and 30 MPG . Use the "between" clause.
- Show the average combined MPG for all compact vehicles.
- How many vehicles have more than 5 cycles?
- What is the minimum number of cycles for all vehicles?
- What is the minimum city MPG for all GMC vehicles that have a displacement between 3 and 4.
- What is the maximum number of cycles for all vehicles?
- How many vehicles made by Chevrolet or Ford have a highway MPG between 30 and 40?
- What is the average highway MPG for vehicles that are not within the range of 6 to 10 cycles?
Hand in the sheet containing the queries. Make sure that both partner's names are on the sheet.
You're done!! Be sure to have the professor or TA check off your work before you leave!!
Copyright © Heidi J. C. Ellis