CIS/336 ilab 5 of 7


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

CIS/336 ilab 5 of 7

  1. 1. CIS/336 iLab 5 of 7 - SQL CourseLab 5 of 7: Retreiving data from Multiple Tables (28 points)LABOVERVIEWScenario/SummaryLab 5 deals with writing queries using multiple tables as covered in the reading and lecture materialthis week. In some cases, you will be given the option to write a query using either theTRADITIONAL method of joining tables or using the JOIN key word. In some cases, you will beasked to use a specific approach. Using the incorrect process when the process is specified willresult in points being taken off for that problem.The SELECT statement is the primary means of extracting data from database tables, and allowsyou to determine exactly which data you want to extract by means of different comparisonoperators used in the WHERE clause. This includes the use of specific "wild card" characters whichallow you to search for character or number patterns within the data. You can also performmathematical expressions within the SELECT statement to create derived output. The ORDER BYclause allows you to sort the output data in either ascending (the default) or descending order. Lab#5 will explore all of these applications of the SELECT statement.General Lab Information and ConsiderationsThis lab will utilize a set of tables found in the script file (LeeBooks.sql) found in the Doc Sharingarea of the website. If you have not yet downloaded this file from Doc Sharing then do so now.Once you have downloaded the script file, import and run the script in SQL*Plus.Each query in the script file you will create must be numbered (use --1 comments for numbering)and in order. The SQL for the following exercises should be written using notepad and run inSQL*Plus.A Clean Script File:A script file is meant to be like a program. The file can be run every time the code needs to beexecuted without having to retype the code again each time. For this reason, it is important thatthere are no errors in the code inside the file. You can go back and forth between Notepad andOracle when creating your script file to check your queries and verify if they work or not, but you donot want to create your final output file until after you have verified that everything in your script is
  2. 2. correct by running it, in its entirety at least once and viewing the output. Once this has been done,you can create your final output file, with echo on to create the document you can turn in with yourlab. If using a Spool Session, be sure to type "SPOOL OFF" AT THE SQL> after your Script StopsSpooling!Lab Dos and Don’tsDo Not include the LEEBOOKS.SQL as part of your lab script.Do use Notepad to write your query script file.Do Not write your queries in Word.Do test each query before moving on to the next.Do Not include extra queries for a problem unless the problem explicitly asks for more than onequery.Do test your queries before creating your final output file.Do Not turn in a script file that has queries with errors.Do number each query using --1 comment notation.Do Not start your query on the same line as the comment.Do remember to check your final output and script file for accuracy.Do Not turn in your lab without first checking your output file to verify that it is correct.Things to keep in mind:If you are not sure of the table names in your user schema, you can use the following selectstatement to list them.
  3. 3. SELECT * FROM TAB;If you want to know the name of the columns in a particular table, you can use the followingcommand to list them.DESCMaking a script file containing a series of describe statements for each table and then spooling theoutput will give you a listing of all the tables with column names.Be sure to review and verify your final output when you are finished. Do Not assume anything.Write queries for each of the stated problems in the steps below that will return a result set of datato satisfy the requirements. When finished, your script file should have a total of 13 queries andyour resulting output file should show both the query and result set for each.DeliverablesSubmit for grading:Your script file with the 13 queries in it. Be sure your name, course number, and lab number are in acomment area at the top of your file. Submitting ONLY your spooled output will result in a 10-pointdeduction.An output file created using SET ECHO ON showing both the SQL code and the results.Both documents must be zipped into a single file before submitting to the iLab Dropbox for Week 5.LABSTEPSSTEP 1:
  4. 4. Using the BOOKS and PUBLISHER tables, create a query using the traditional join method that willreturn a list containing the book title, publisher contact person, and publisher phone number for allpublishers whose publisher name starts with an „R‟.STEP 2:Using the DUAL table, create a query that will return the day of the week, hour, minutes, andseconds of the current date setting on a computer. The day should be in all upper case.STEP 3:Using the BOOK_CUSTOMER and BOOK_ORDER tables, create a query using the NATURAL JOINmethod that will return a list containing the customer first name and last name and the ordernumber for all orders that have been shipped. Give the customer name column an alias of"Customer Name" and order the output by the customer number in the BOOK_ORDER table inascending order.STEP 4:Using the BOOK_ORDER table, create a query that will return the order number, order date,shipping address, city, state, and zip code for all orders going to Atlanta or Austin. Format the orderdate to display as Month DD, YYYY and give the column an alias of "Date Ordered". Be sure themonth begins with a capital letter.STEP 5:Using the BOOK_ORDER table, create a query using the correct function to return the order number,the date ordered, the date shipped, and a column representing the number of months between thetwo dates for all columns where a date shipped exists. Format the number returned from thefunction to display only two decimals, and give the column an alias of "Months Between".NOTE: Be sure that all of the numbers in the fourth column are positive numbers.STEP 6:Using the correct tables in your schema, create a query using either join operation that will list thetitle of each book and author name(s). Give the title column an alias of "Book Title". Sort the resultsby title and then by author last name.STEP 7:Using the BOOKS table, create a query that will return the book title, cost, and retail price for allbooks with a title starting with the letter „H‟. Use the correct conversion function to format the costand retail columns to show dollars and cents with a dollar sign (e.g., a price of $25 would display$25.00 in the result set).STEP 8:
  5. 5. Using the BOOK_ORDER, ORDER_ITEMS, and BOOKS tables, create a query using an OUTER JOINoperation that will list the book title, order date, and order number for all books in the BOOKS table.Order your output in descending order by ORDER_ITEMS.BOOKID. There are three books that havenever been ordered which should show up at the top of your listing.STEP 9:Using the correct tables, create a query using the traditional join operation that will list the customerfirst and last name, book title, and order date (formatted as MM/DD/YYYY with an alias of “OrderDate”) for all the customers who have purchased books published by PRINTING IS US.STEP 10:Using the BOOKS and ORDER_ITEMS table, write a query using the correct Relational Set Operatorthat will show all of the Book IDs in the BOOKS table that have not been ordered.STEP 11:Using the BOOK_CUSTOMER, BOOK_ORDER, ORDER_ITEMS, and BOOKS tables, create a queryusing traditional join conditions based on comparisons between primary and foreign keys that willlist the customer number, first and last name, and book title. Limit your listing to only those books inthe „FITNESS‟ category.STEP 12:Using the BOOKS, ORDER_ITEMS, and BOOK_ORDER tables, create a query that will list the title,retail, quantity, and order date for all books ordered after April 30, 2009.STEP 13:Using the correct tables, create a query using either join operation you wish that will list the orderid, order date, quantity ordered, and retail price for every book that has been ordered. Format thedate as MM/DD/YYYY with an alias of “Order Date” and format the retail price column using thecorrect function to show dollars and cents with a dollar sign ( $ ) and a column alias of “Retail”.This is the end of lab #5CLICK HERE TO GET THE SOLUTION !!!!!!!!!!