Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LAB OVERVIEW Lab 4 will introduce the various aspects of the SQL select statement and the methods of retrieving data from the database tables. This

LAB OVERVIEW

Lab 4 will introduce the various aspects of the SQL select statement and the methods of retrieving data from the database tables. This lab will also introduce the fundamentals of updating and deleting records. This lab may be completed using either DeVrys Omnymbus EDUPE-APP lab environment, or a local copy of the MySQL database running on your own computer using the OM database tables. The lab will utilize a set of tables that are represented by the ERD (OM_ERD.docx) and are created and populated by the script file (create_OM_db.sql). Follow the instructions in the file CreateOMTables.docx to create your database, tables, and data.

image text in transcribed

A few IMPORTANT things to note if using EDUPE MySQL:

**There can be NO SPACES in alias names given to a column. For example:

Select unit_price as Retail Price from items; --this does NOT work in EDUPE MySQL.

Any of the following WILL WORK:

Select unit_price as "RetailPrice" from items;

Select unit_price as "Retail_Price" from items;

Select unit_price as Retail_Price from items;

Select unit_price as RetailPrice from items;

**Any calculated fields MUST be given an alias (and note above NO SPACES in alias). For example:

select unit_price * 2 from items; --this does NOT work in EDUPE MySQL

This will work:

select unit_price * 2 as NewPrice from items;

Deliverables

Lab Report (Answer Sheet) containing both the student-created SQL command(s) for each exercise, and the output showing the results obtained. Be sure your name is on the file.

LAB STEPS: Complete each of the exercises below.

Write a query that displays a list of all customers showing the customer first name, last name, and phone number. Sort the results by customer last name, then first name.

Write a query that displays each customer name as a single field in the format firstname lastname with a heading of Customer, along with their phone number with a heading of Phone. Use the IN operator to only display customers in New York, New Jersey, or Washington D.C. Sort the results by phone number.

Write a query that will list all the cities that have customers with a heading of Cities. Only list each city once (no duplicates) and sort in descending alphabetical order.

Write a query that displays the title of each item along with the price (with a heading of Original) and a calculated field reflecting the price with a 25% discount (with a heading of Sale). Display the sale price with two decimal places using the ROUND function. Sort by price from lowest to highest.

Write a query that displays the customer_first_name, customer_last_name, and customer_city from the customers table. Use the LIKE operator to only display customers that reside in any zipcode beginning with 4.

Write a query that displays the order id and order date for any orders placed from March 1, 2014 through April 30, 2014. Do this WITHOUT using the BETWEEN clause. Format the date field as Month dd, yyyy and use a heading of Ordered.

Write a query that displays the order id and order date for any orders placed during the month of May, 2014. Do this using the BETWEEN clause. Format the date field as mm/dd/yy and use a heading of Ordered.

Write a query which displays the order id, customer id, and the number of days between the order date and the ship date (use the DATEDIFF function). Name this column Days and sort by highest to lowest number of days. Only display orders where this result is 15 days or more.

Write a query which displays the order id, customer id and order date for all orders that have NOT been shipped, sorted by order date with the most recent order at the top.

The Marketing Department has requested a new report of shipped orders for which the order was placed on either a Saturday or a Sunday. Write a query which displays the order id, order date, shipped date, along with a calculated column labeled Order_Day showing the day of the week the order was placed (use the DAYNAME function). Only display orders that have shipped and were placed on a Saturday or Sunday. Sort by order date with most recent orders at the top.

Write a query to display the customer last name, phone number, and fax number but only display those customers that have a fax number.

Create a statement to insert a new record into the items table with the following values:

item_id:

11

title:

Ode To My ERD

Artist_id:

15

unit_price:

12.95

Show your INSERT statement along with the results of the following SELECT query to verify that the insert worked correctly.

select * from items where item_id > 10;

Create a statement to update the record inserted in the previous step to change the unit price of this item to 7.95.

item_id:

11

title:

Ode To My ERD

artist:

15

unit_price:

7.95

Show your UPDATE statement along with the results of the following SELECT query to verify that the insert worked correctly.

select * from items where item_id > 10;

Create a statement to delete the entire record that was inserted and then updated in the previous steps.

Show your DELETE statement along with the results of the following SELECT query to verify that the insert worked correctly.

select * from items where item_id > 10;

Using the SUBSTRING and CONCAT functions, write a query to display each customer name as a single field in the format Jones, Tom with a heading of Customer along with the customer_phone field in a nicely formatted calculated column named Phone. For example, a record containing the customer_phone value 6145535443 would be output with parentheses, spaces, and hyphens, like this: (614) 555-5443. Sort by last name.

This is the end of Lab 4.

Database Model for Labs 4-7 customers PK customer id INTEGER orders PK order id INTEGER customer_first_name VARCHAR(20) customerlast name VARCHAR(20) customer_address VARCHAR(50) customer_city customer_state customer_zip customer phone CHAR(10) customer fax order_date DATETIME shipped_date DATETIME VARCHAR(20) CHAR(2) CHAR(5) FK1 customer id INTEGER FK2 employee_id INTEGER CHAR(10) Employees order details id INTEGER PK,FK1 order id INTEGER PK,FK2 item idINTEGER last_name VARCHAR(20) first name VARCHAR(20) FK1 manager idINTEGER order qty INTEGER tems Artists PK item id INTEGER PK artist id INTEGER title unit_price DECIMAL(9,2) VARCHAR(40) artist_name VARCHAR(30) FK1 artist id INTEGER

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions

Question

Define Management by exception

Answered: 1 week ago

Question

Explain the importance of staffing in business organisations

Answered: 1 week ago

Question

What are the types of forms of communication ?

Answered: 1 week ago