The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 305 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Having issues with an sql assignment. Details attached below. (SQL command(s) for each exercise, and the output showing the results obtained)
**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 STEPS: Complete each of the exercises below.
1. 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.
2. Write a query that displays each customer name as a single field in the format “firstnamelastname” 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.
3. 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.
4. 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 ROUNDfunction. Sort by price from lowest to highest.
5. 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.
6. 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”.
7. 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”.
8. 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.
9. 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.
10. 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.
11. Write a query to display the customer last name, phone number, and fax number but only display those customers that have a fax number.
12. 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;
13. 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;
14. 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;
15. 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.
~Paste your solution query here~
~Paste your solution query results text here~
~Paste your solution query here~
~Paste your solution query results text here~
~Paste your solution query here~
~Paste your solution query results text here~
~Paste your solution query here~
~Paste your solution query results text here~
~Paste your solution query here~
~Paste your solution query results text here~
~Paste your solution query here~
~Paste your solution query results text here~
~Paste your solution query here~
~Paste your solution query results text here~
~Paste your solution query here~
~Paste your solution query results text here~
~Paste your solution query here~
~Paste your solution query results text here~
~Paste your solution query here~
~Paste your solution query results text here~
~Paste your solution query here~
~Paste your solution query results text here~
~Paste your solution query here~
~Paste your solution query results text here~
~Paste your solution query here~
~Paste your solution query results text here~
~Paste your solution query here~
~Paste your solution query results text here~
~Paste your solution query here~
~Paste your solution query results text here~
----------- ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly