SlideShare uma empresa Scribd logo
1 de 5
CIS/336 iLab 5 of 7 - SQL Course

Lab 5 of 7: Retreiving data from Multiple Tables (28 points)

LABOVERVIEW

Scenario/Summary



Lab 5 deals with writing queries using multiple tables as covered in the reading and lecture material
this week. In some cases, you will be given the option to write a query using either the
TRADITIONAL method of joining tables or using the JOIN key word. In some cases, you will be
asked to use a specific approach. Using the incorrect process when the process is specified will
result in points being taken off for that problem.



The SELECT statement is the primary means of extracting data from database tables, and allows
you to determine exactly which data you want to extract by means of different comparison
operators used in the WHERE clause. This includes the use of specific "wild card" characters which
allow you to search for character or number patterns within the data. You can also perform
mathematical expressions within the SELECT statement to create derived output. The ORDER BY
clause 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 Considerations

This lab will utilize a set of tables found in the script file (LeeBooks.sql) found in the Doc Sharing
area 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 in
SQL*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 be
executed without having to retype the code again each time. For this reason, it is important that
there are no errors in the code inside the file. You can go back and forth between Notepad and
Oracle when creating your script file to check your queries and verify if they work or not, but you do
not want to create your final output file until after you have verified that everything in your script is
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 your
lab. If using a Spool Session, be sure to type "SPOOL OFF" AT THE SQL> after your Script Stops
Spooling!



Lab Do's and Don’t's

Do 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 one
query.



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 select
statement to list them.
SELECT * FROM TAB;



If you want to know the name of the columns in a particular table, you can use the following
command to list them.



DESC



Making a script file containing a series of describe statements for each table and then spooling the
output 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 data
to satisfy the requirements. When finished, your script file should have a total of 13 queries and
your resulting output file should show both the query and result set for each.




Deliverables

Submit for grading:

Your script file with the 13 queries in it. Be sure your name, course number, and lab number are in a
comment area at the top of your file. Submitting ONLY your spooled output will result in a 10-point
deduction.



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.



LABSTEPS



STEP 1:
Using the BOOKS and PUBLISHER tables, create a query using the traditional join method that will
return a list containing the book title, publisher contact person, and publisher phone number for all
publishers 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, and
seconds 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 JOIN
method that will return a list containing the customer first name and last name and the order
number 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 in
ascending 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 order
date to display as Month DD, YYYY and give the column an alias of "Date Ordered". Be sure the
month 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 the
two dates for all columns where a date shipped exists. Format the number returned from the
function 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 the
title of each book and author name(s). Give the title column an alias of "Book Title". Sort the results
by 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 all
books with a title starting with the letter „H‟. Use the correct conversion function to format the cost
and 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:
Using the BOOK_ORDER, ORDER_ITEMS, and BOOKS tables, create a query using an OUTER JOIN
operation 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 have
never 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 customer
first and last name, book title, and order date (formatted as MM/DD/YYYY with an alias of “Order
Date”) 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 Operator
that 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 query
using traditional join conditions based on comparisons between primary and foreign keys that will
list the customer number, first and last name, and book title. Limit your listing to only those books in
the „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 order
id, order date, quantity ordered, and retail price for every book that has been ordered. Format the
date as MM/DD/YYYY with an alias of “Order Date” and format the retail price column using the
correct function to show dollars and cents with a dollar sign ( $ ) and a column alias of “Retail”.



This is the end of lab #5


CLICK HERE TO GET THE SOLUTION !!!!!!!!!!

Mais conteúdo relacionado

Mais procurados (10)

Schema plus
Schema plusSchema plus
Schema plus
 
6 ref works 2.0 search online databases in refworks 2.0
6 ref works 2.0 search online databases in refworks 2.06 ref works 2.0 search online databases in refworks 2.0
6 ref works 2.0 search online databases in refworks 2.0
 
Dynamics AX DMF vendor and its alternate address
Dynamics AX DMF vendor and its alternate addressDynamics AX DMF vendor and its alternate address
Dynamics AX DMF vendor and its alternate address
 
PERRLA Info Sheet
PERRLA Info SheetPERRLA Info Sheet
PERRLA Info Sheet
 
Unit 2 web technologies
Unit 2 web technologiesUnit 2 web technologies
Unit 2 web technologies
 
RefWorks, Intro
RefWorks, IntroRefWorks, Intro
RefWorks, Intro
 
Formatting Using References List
Formatting Using References ListFormatting Using References List
Formatting Using References List
 
RefWorks How to version 1
RefWorks How to version 1RefWorks How to version 1
RefWorks How to version 1
 
Phpmyadmin administer mysql
Phpmyadmin administer mysqlPhpmyadmin administer mysql
Phpmyadmin administer mysql
 
Chapter.05
Chapter.05Chapter.05
Chapter.05
 

Destaque (6)

Civilizaciones Azteca, Zapoteca y Maya con Cabañas en Tulum
Civilizaciones Azteca, Zapoteca y Maya con Cabañas en TulumCivilizaciones Azteca, Zapoteca y Maya con Cabañas en Tulum
Civilizaciones Azteca, Zapoteca y Maya con Cabañas en Tulum
 
Information is correct, knowledge is relevant
Information is correct, knowledge is relevantInformation is correct, knowledge is relevant
Information is correct, knowledge is relevant
 
Blogging
BloggingBlogging
Blogging
 
Yr10 set1 RandJ 14/3/08
Yr10 set1 RandJ 14/3/08Yr10 set1 RandJ 14/3/08
Yr10 set1 RandJ 14/3/08
 
How (Not) To Write A Book
How (Not) To Write A BookHow (Not) To Write A Book
How (Not) To Write A Book
 
20100302 Dinamiche di Team Brainstorming @UniRM3 Roma-IT [ITA]
20100302 Dinamiche di Team Brainstorming @UniRM3 Roma-IT [ITA]20100302 Dinamiche di Team Brainstorming @UniRM3 Roma-IT [ITA]
20100302 Dinamiche di Team Brainstorming @UniRM3 Roma-IT [ITA]
 

Semelhante a CIS/336 ilab 5 of 7

Cis336 week 5 i lab5
Cis336 week 5 i lab5Cis336 week 5 i lab5
Cis336 week 5 i lab5
wefsfewf
 
Cis336 week 5 i lab5
Cis336 week 5 i lab5Cis336 week 5 i lab5
Cis336 week 5 i lab5
xcvxbdfbdf
 
Cis336 week 5 i lab 5
Cis336 week 5 i lab 5Cis336 week 5 i lab 5
Cis336 week 5 i lab 5
CIS339
 
Cis336 week 5 i lab 5
Cis336 week 5 i lab 5Cis336 week 5 i lab 5
Cis336 week 5 i lab 5
jackiechaner
 
Cis336 week 4 i lab 4
Cis336 week 4 i lab 4Cis336 week 4 i lab 4
Cis336 week 4 i lab 4
CIS339
 
Cis336 week 4 i lab 4
Cis336 week 4 i lab 4Cis336 week 4 i lab 4
Cis336 week 4 i lab 4
jackiechaner
 
Cis336 week 7 i lab 7
Cis336 week 7 i lab 7Cis336 week 7 i lab 7
Cis336 week 7 i lab 7
CIS339
 
Advanced Spreadsheet Skills-1.pptx
Advanced Spreadsheet Skills-1.pptxAdvanced Spreadsheet Skills-1.pptx
Advanced Spreadsheet Skills-1.pptx
CliffordBorromeo
 
ECET 450 Laboratory 2Lab 2 involves two parts.Part A involv.docx
ECET 450 Laboratory 2Lab 2 involves two parts.Part A involv.docxECET 450 Laboratory 2Lab 2 involves two parts.Part A involv.docx
ECET 450 Laboratory 2Lab 2 involves two parts.Part A involv.docx
jenkinsmandie
 
BUSI 301 Book Review RubricScoreCommentsResearch 25.docx
BUSI 301 Book Review RubricScoreCommentsResearch 25.docxBUSI 301 Book Review RubricScoreCommentsResearch 25.docx
BUSI 301 Book Review RubricScoreCommentsResearch 25.docx
humphrieskalyn
 
ECET 450 Laboratory 2Part BPurposeThis laborato.docx
ECET 450 Laboratory 2Part BPurposeThis laborato.docxECET 450 Laboratory 2Part BPurposeThis laborato.docx
ECET 450 Laboratory 2Part BPurposeThis laborato.docx
jack60216
 
CS1100 Access Lab 1 Creating and Querying Database.docx
CS1100 Access Lab 1  Creating and Querying Database.docxCS1100 Access Lab 1  Creating and Querying Database.docx
CS1100 Access Lab 1 Creating and Querying Database.docx
faithxdunce63732
 

Semelhante a CIS/336 ilab 5 of 7 (20)

Cis336 week 5 i lab5
Cis336 week 5 i lab5Cis336 week 5 i lab5
Cis336 week 5 i lab5
 
Cis336 week 5 i lab5
Cis336 week 5 i lab5Cis336 week 5 i lab5
Cis336 week 5 i lab5
 
Cis336 week 5 i lab5
Cis336 week 5 i lab5Cis336 week 5 i lab5
Cis336 week 5 i lab5
 
Cis336 week 5 i lab5
Cis336 week 5 i lab5Cis336 week 5 i lab5
Cis336 week 5 i lab5
 
Cis336 week 5 i lab5
Cis336 week 5 i lab5Cis336 week 5 i lab5
Cis336 week 5 i lab5
 
Cis336 week 5 i lab 5
Cis336 week 5 i lab 5Cis336 week 5 i lab 5
Cis336 week 5 i lab 5
 
Cis336 week 5 i lab 5
Cis336 week 5 i lab 5Cis336 week 5 i lab 5
Cis336 week 5 i lab 5
 
Cis336 week 5 i lab 5
Cis336 week 5 i lab 5Cis336 week 5 i lab 5
Cis336 week 5 i lab 5
 
Cis336 week 4 i lab 4
Cis336 week 4 i lab 4Cis336 week 4 i lab 4
Cis336 week 4 i lab 4
 
Cis336 week 4 i lab 4
Cis336 week 4 i lab 4Cis336 week 4 i lab 4
Cis336 week 4 i lab 4
 
Cis336 week 4 i lab 4
Cis336 week 4 i lab 4Cis336 week 4 i lab 4
Cis336 week 4 i lab 4
 
Cis336 week 7 i lab 7
Cis336 week 7 i lab 7Cis336 week 7 i lab 7
Cis336 week 7 i lab 7
 
Advanced Spreadsheet Skills-1.pptx
Advanced Spreadsheet Skills-1.pptxAdvanced Spreadsheet Skills-1.pptx
Advanced Spreadsheet Skills-1.pptx
 
9 - Advanced Functions in MS Excel.pptx
9 - Advanced Functions in MS Excel.pptx9 - Advanced Functions in MS Excel.pptx
9 - Advanced Functions in MS Excel.pptx
 
ECET 450 Laboratory 2Lab 2 involves two parts.Part A involv.docx
ECET 450 Laboratory 2Lab 2 involves two parts.Part A involv.docxECET 450 Laboratory 2Lab 2 involves two parts.Part A involv.docx
ECET 450 Laboratory 2Lab 2 involves two parts.Part A involv.docx
 
microsoft excel february 2, 2020 (2).pptx [Autosaved].pptx
microsoft excel february 2, 2020 (2).pptx [Autosaved].pptxmicrosoft excel february 2, 2020 (2).pptx [Autosaved].pptx
microsoft excel february 2, 2020 (2).pptx [Autosaved].pptx
 
BUSI 301 Book Review RubricScoreCommentsResearch 25.docx
BUSI 301 Book Review RubricScoreCommentsResearch 25.docxBUSI 301 Book Review RubricScoreCommentsResearch 25.docx
BUSI 301 Book Review RubricScoreCommentsResearch 25.docx
 
Handouts how to use microsoft access to conduct an overlap analysis
Handouts how to use microsoft access to conduct an overlap analysisHandouts how to use microsoft access to conduct an overlap analysis
Handouts how to use microsoft access to conduct an overlap analysis
 
ECET 450 Laboratory 2Part BPurposeThis laborato.docx
ECET 450 Laboratory 2Part BPurposeThis laborato.docxECET 450 Laboratory 2Part BPurposeThis laborato.docx
ECET 450 Laboratory 2Part BPurposeThis laborato.docx
 
CS1100 Access Lab 1 Creating and Querying Database.docx
CS1100 Access Lab 1  Creating and Querying Database.docxCS1100 Access Lab 1  Creating and Querying Database.docx
CS1100 Access Lab 1 Creating and Querying Database.docx
 

Mais de ashhadiqbal

Mais de ashhadiqbal (15)

Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6
 
Cis 355 ilab 3 of 6
Cis 355 ilab 3 of 6Cis 355 ilab 3 of 6
Cis 355 ilab 3 of 6
 
Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6
 
Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6
 
Cis 355 ilab 6 of 6
Cis 355 ilab 6 of 6Cis 355 ilab 6 of 6
Cis 355 ilab 6 of 6
 
Ilab 2 of 7
Ilab 2 of 7Ilab 2 of 7
Ilab 2 of 7
 
Comp 220 ilab 6 of 7
Comp 220 ilab 6 of 7Comp 220 ilab 6 of 7
Comp 220 ilab 6 of 7
 
Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7
 
Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7
 
Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7
 
CIS/336 ilab 1 of 7
CIS/336 ilab 1 of 7CIS/336 ilab 1 of 7
CIS/336 ilab 1 of 7
 
CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7
 
PRG/421 Week 4
PRG/421 Week 4PRG/421 Week 4
PRG/421 Week 4
 
PRG/421 Week 2
PRG/421 Week 2PRG/421 Week 2
PRG/421 Week 2
 
PRG/421 Week 1
PRG/421 Week 1PRG/421 Week 1
PRG/421 Week 1
 

CIS/336 ilab 5 of 7

  • 1. CIS/336 iLab 5 of 7 - SQL Course Lab 5 of 7: Retreiving data from Multiple Tables (28 points) LABOVERVIEW Scenario/Summary Lab 5 deals with writing queries using multiple tables as covered in the reading and lecture material this week. In some cases, you will be given the option to write a query using either the TRADITIONAL method of joining tables or using the JOIN key word. In some cases, you will be asked to use a specific approach. Using the incorrect process when the process is specified will result in points being taken off for that problem. The SELECT statement is the primary means of extracting data from database tables, and allows you to determine exactly which data you want to extract by means of different comparison operators used in the WHERE clause. This includes the use of specific "wild card" characters which allow you to search for character or number patterns within the data. You can also perform mathematical expressions within the SELECT statement to create derived output. The ORDER BY clause 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 Considerations This lab will utilize a set of tables found in the script file (LeeBooks.sql) found in the Doc Sharing area 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 in SQL*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 be executed without having to retype the code again each time. For this reason, it is important that there are no errors in the code inside the file. You can go back and forth between Notepad and Oracle when creating your script file to check your queries and verify if they work or not, but you do not want to create your final output file until after you have verified that everything in your script is
  • 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 your lab. If using a Spool Session, be sure to type "SPOOL OFF" AT THE SQL> after your Script Stops Spooling! Lab Do's and Don’t's Do 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 one query. 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 select statement to list them.
  • 3. SELECT * FROM TAB; If you want to know the name of the columns in a particular table, you can use the following command to list them. DESC Making a script file containing a series of describe statements for each table and then spooling the output 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 data to satisfy the requirements. When finished, your script file should have a total of 13 queries and your resulting output file should show both the query and result set for each. Deliverables Submit for grading: Your script file with the 13 queries in it. Be sure your name, course number, and lab number are in a comment area at the top of your file. Submitting ONLY your spooled output will result in a 10-point deduction. 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. LABSTEPS STEP 1:
  • 4. Using the BOOKS and PUBLISHER tables, create a query using the traditional join method that will return a list containing the book title, publisher contact person, and publisher phone number for all publishers 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, and seconds 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 JOIN method that will return a list containing the customer first name and last name and the order number 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 in ascending 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 order date to display as Month DD, YYYY and give the column an alias of "Date Ordered". Be sure the month 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 the two dates for all columns where a date shipped exists. Format the number returned from the function 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 the title of each book and author name(s). Give the title column an alias of "Book Title". Sort the results by 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 all books with a title starting with the letter „H‟. Use the correct conversion function to format the cost and 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. Using the BOOK_ORDER, ORDER_ITEMS, and BOOKS tables, create a query using an OUTER JOIN operation 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 have never 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 customer first and last name, book title, and order date (formatted as MM/DD/YYYY with an alias of “Order Date”) 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 Operator that 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 query using traditional join conditions based on comparisons between primary and foreign keys that will list the customer number, first and last name, and book title. Limit your listing to only those books in the „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 order id, order date, quantity ordered, and retail price for every book that has been ordered. Format the date as MM/DD/YYYY with an alias of “Order Date” and format the retail price column using the correct function to show dollars and cents with a dollar sign ( $ ) and a column alias of “Retail”. This is the end of lab #5 CLICK HERE TO GET THE SOLUTION !!!!!!!!!!