SOLUTIONJUG.COMCIS/336 iLab 6 of 7 - SQL CourseCLICK HERE TO GET THE SOLUTION !!!!!!!!Oracle Single Row and Group Function...
o Do remember to check your final output and script file for accuracy.• Do Not turn in your lab without first checking you...
Using the BOOK_AUTHOR and AUTHOR tables for the upper most query, create a sub query thatwill return the BOOKID, and the f...
select on the BOOKS table after the update. Once you have verified the results, you can issue aROLLBACK statement to retur...
Upcoming SlideShare
Loading in...5
×

Cis 336 ilab 6 of 7

61

Published on

Lab #6 will introduce the various aspects of the Single-Row and Group Functions available in the Oracle Database. Most functions can be used in either the SELECT statement or the WHERE clause, but more commonly are used in the SELECT. Chapters 5 and 6 cover most all of the normal processing you use in these functions. In some cases, you will be asked to used more than one function within a single SELECT statement.

General Lab Information and Considerations

This lab will utilize the same set of tables found in the script file (LeeBooks.SQL) that were used for Labs 4 and 5.

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 in SQL*Plus. Read each problem carefully and follow the directions as stated.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
61
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Cis 336 ilab 6 of 7"

  1. 1. SOLUTIONJUG.COMCIS/336 iLab 6 of 7 - SQL CourseCLICK HERE TO GET THE SOLUTION !!!!!!!!Oracle Single Row and Group FunctionsL A B O V E R V I E WScenario/SummaryLab #6 will introduce the various aspects of the Single-Row and Group Functions available in theOracle Database. Most functions can be used in either the SELECT statement or the WHERE clause,but more commonly are used in the SELECT. Chapters 5 and 6 cover most all of the normalprocessing you use in these functions. In some cases, you will be asked to used more than onefunction within a single SELECT statement.General Lab Information and ConsiderationsThis lab will utilize the same set of tables found in the script file (LeeBooks.SQL) that were used forLabs 4 and 5.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. Read each problem carefully and follow the directions as stated.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. However,you do not want to create your final output file until after you have verified that everything in yourscript is correct by running it, in its entirety at least once and viewing the output. Once this hasbeen done, you can create your final output file, with echo to create the document, you can turn inwith your lab. Remember in using a spool session, you must type "SPOOL OFF" at the SQL> promptafter your script stops spooling to capture all of your data!Lab Dos and Don’ts• Do Not include the LEEBOOKS.SQL as part of your lab script.o Do use Notepad to write your query script file.• Do Not write your queries in Word.o Do test each query before moving on to the next.• Do Not include extra queries for a problem unless the problem explicitly asks for morethan one query.o Do test your queries before creating your final output file.• Do Not turn in a script file that has queries with errors.o Do number each query using - -1 comment notation.• Do Not start your query on the same line as the comment.
  2. 2. o 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.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:1. Your script file with the 13 queries in it. Be sure your name, course number, and labnumber are in a comment area at the top of your file.2. An output file created using SET ECHO ON showing both the SQL code and the results.3. Both documents are to be zipped into a single file before submitting to the iLab Dropboxfor Week 6.L A B S T E P SSTEP 1:Using the BOOK_CUSTOMER table and the NVL function, create a query that will return a listcontaining the customer number, first name, last name, and the characters ‘NOT REFERRED’ if thecustomer was not referred by another customer. Give the derived column an alias of REFERRED BY.Do not list any customers that were referred by another customer.STEP 2:Using the BOOKS table and the SUBSTR function, create a query that will return a list of book ISBNcodes and the book title for all the computer books. Format the ISBN code to display as 9-999-99999-9 (e.g., 1059831198 would display as 1-059-83119-8)STEP 3:Using the BOOKS table, create a query using the correct functions to return the category name, thetotal retail of all books per category with a column alias of "Total Retail", and the average retail of allthe books per category with an alias of "Average Retail" for all categories with a total retail greaterthan $40.00. Format the total retail and average retail columns using the correct function to showdollars and cents with a dollar sign.STEP 4:Using the correct tables in your schema, create a query using either join operation you wish that willlist the book title and number of authors for all books that have been written by more than oneauthor. Give the title column an alias of "Book Title" and the column showing the number of authorsan alias of "Number of Authors".STEP 5:
  3. 3. Using the BOOK_AUTHOR and AUTHOR tables for the upper most query, create a sub query thatwill return the BOOKID, and the first and last name of the author(s) who have written the book(s)that have been purchased the most. To successfully accomplish this, you will need to first find outthe maximum total number of copies (based on quantity) sold of a book (based on bookid) in theORDER_ITEMS table. This will be done in the bottom most query. The return from this query will beused to compare against the BOOKID in the ORDER_ITEMS table that occurs an equal number oftimes in the middle query. The return of this query will then be used to compare to a BOOKIDrelated to an Author in the tables of the top most query. (HINT: Be careful, you will need bothGROUP BY and HAVING clauses for your solution.)STEP 6:Using the correct tables, create a sub query using either join operation you wish that will list thecustomer number, first and last name concatenated together, and city for all customers who haveplaced an order for the most expensive book (based on retail price). Give the combined customernames column and alias of "Customer Name".STEP 7:Using the ORDER_ITEMS table, create a query using the correct functions to return the item#, thetotal quantity of items ordered with an alias of "Total", the average quantity per order with an aliasof "Average" (since averages are often in decimals, only show two decimal places), the minimumquantity ordered with an alias of "Minimum", and the maximum quantity ordered with an alias of"Maximum". Your output results set should have five columns and four rows of data.STEP 8:Using the BOOKS table, create a query using the DECODE function that will display the book title,the published date, and the publisher name (this is where the decode function comes in). Give thepublisher name column an alias of "Publisher Name", and order the publisher names in descendingorder. The publisher names used should be the same as those in the PUBLISHER table. DO NOT jointo the Publisher table for this query.STEP 9:Using the PUBLISHER table, create a query that will return a line of output like the one below foreach record in the table. Be sure to use the correct functions in the SELECT statement, so that youroutput looks like the example below.The contact person for Printing Is Us Publishing is Tommie Seymour.Be sure to use the correct function to display the publisher name and publisher contact with only thefirst letter of each word capitalized.STEP 10:Using the correct tables, create a query using the JOIN ON method to display a listing of allcustomers who have purchased more than two books. List the customer’s last name, the customer’scity and state, and the number of books they have purchased. Give the number purchased columnand alias of "Number Purchased".STEP 11:Using only the BOOK table for the upper most statement, create a sub query that will update theretail price of all books published by PRINTING IS US by five percent (retail * 1.05). Remember, allyou have is the publisher "name". Use the sub query to find the publisher ID. To verify your update,provide a select statement on the BOOKS table before your update statement, and then a second
  4. 4. select on the BOOKS table after the update. Once you have verified the results, you can issue aROLLBACK statement to return the data to the original state.STEP 12:Using the BOOK_CUSTOMER table, write a sub query that will return the names of those customerswho were referred by the same individual who referred Jorge Perez. Do not display Jorge Perez’sname in the returned results (Hint: you should only have two customers displayed and the exclusionfor Jorge Perez must be associated with the upper query).STEP 13:Using the BOOKS table, create a query using the correct functions to return the category name, totalnumber books per category with a column alias of "Category Total", and the total cost of all thebooks per category with an alias of "Cost". Format the cost column using the correct function toshow dollars and cents with a dollar sign.This is the end of Lab #6CLICK HERE TO GET THE SOLUTION !!!!!!!!

×