Assignment: Single Table Queries
- Purpose: Create queries to retrieve specific data from a table in the database.
- Task: Code single table queries using clauses, keywords, operators and functions.
Instructions:
- Using the v_art, bike, and magazine databases, write queries in Workbench that will solve all the answers to the following scenarios. In addition to using sql clauses and functions properly, this assignment is about problem-solving; analyzing what is being asked, and breaking the problem to solve into steps leading to the solution.
- All the queries will be written on one tab in Workbench, save the SQL script with all 15 queries and submit the single .sql file.
- Please use comments to number your queries.
Virtual Art Gallery Application Queries:
Queries 1–4 will be queries that are coded to run the back-end CMS of the virtual art gallery application. Screenshots below are from that CMS.
-
The manager wants to add the artist Johannes Vermeer as an artist in the database. He was born in 1632 and is from the Netherlands and died in 1674. He is not a local artist. What would the insert statement look like that would run as the manager adds a new artist to the system? (The following image is a screenshot of the backend of the system that the manager of the art gallery would see. We are interested only in the SQL statement that would run in the code when a new artist is added.)
-
If the manager lists all the artists with 'List all Artist Records' the following screen renders sorted by the last name of the artist. What query would allow all seven columns of values to show up on the screen alphabetically by the last name?
-
The manager wants to edit Vermeer's information. She finds out that he died in 1675, not 1674. She selects EDIT next to Johannes Vermeer the following screen displays. The manager changes the 'Date of Death' value to be 1675 and selects 'Update Entry'. What SQL statement will run in the background to accomplish this edit? (Don't forget a WHERE clause!)
-
The manager decides that she wants to delete Vermeer as an artist from her database. She selects the DELETE next to the Vermeer's row of information and the following screen renders confirming that she really wants to delete Vermeer as an artist. What SQL statement will run in the code that would delete Johannes Vermeer from the database when the manager selects 'Confirm Deletion'? (Don't forget a WHERE clause!)
Bike Shop Queries:
Create queries that the bike shop may need for the following business purposes.
-
There is a product demonstration and bike race planned in Houston, Texas and you'd like to text each of your customers from that city to see if they will participate. You need a list of their first and last names and phone numbers.
Your result set should look like this with nine customers:
-
You need to sell more of your high-end bikes. You want to take $500 off all bikes that have a list price of $5,000.00 or more. You need to have a list showing the bike name, list price and discount price with an alias of 'Discount Price'. Sort the list showing the most expensive bike first. The result set will look like this:
-
An important announcement was given to all the staff at your store (store_id 1). The same announcement needs to get to all the other staff at the other stores. You don't want to email all your staff again. You need a list of all the staff and their email who are not from your store.
-
A customer needs more information about a specific bike, but all they know is that is has the word 'spider' in the name. You need to list the name, model year, and list price of all the bikes with the word 'spider' somewhere in the name.
-
You need to list all bikes names that have a range of prices from $500–$550 sorted with the lowest price first.
-
Show the customer's first_name, last_name, phone, street, city, state, zip_code who:
- have a phone number listed
- and whose city has the letters 'ach' or 'och' somewhere in their name of the city
- or whose last name is William.
Limit the result set to the first five results.
-
We need a list of all the products without the year at the end of the product_name string. Notice that some have two years listed, make sure you take those off as well. Order your results by product_id and limit your results to the first 14.
-
List the product name and then take the 2019 model year bikes and divide the price into 3 equal payments. Display one of the payments with a dollar sign, comma at the thousands place and two decimal places.
Magazine Database:
-
List the magazine name and then take 3% off the magazine price and round to 2 decimal places.
- Show the primary key of id from the subscriber table and using the date of 2020-12-20 as if it were today's date, how long in years, ROUNDED to the nearest year, has it been since their subscription started?
- Show the subscriptionStartDate and subscriptionLength and add the subscriptionLength to the subscriptionStartDate to see the date of how long their subscription will go. Format that date so it takes the format of Month name, number day with comma and then a 4 digit year.
Submission
Upload a single .sql query file to Canvas that contains queries for each of the 10 scenarios. Make sure to add a comment at the top of each query with the scenario number it is solving.
Useful Links:
- Next Activity: Complete W01 Prove Quiz and W01 60-second Status Update in Canvas
- Previous Activity: Team Activity: Querying Company Data
- Go to: Week Index • Course Home • Canvas