CIT 111: Introduction to Databases

Assignment: Joining and Summarizing Data

Instructions

  1. Using the v_art, magazine and employee databases, write queries in Workbench to solve all the answers to the following scenarios.
  2. All the queries will be written in one tab in Workbench and then save the SQL script with all the queries and submit that .sql file.
  3. Please use comments to number your queries. 
  4. Note: the exact steps required are not supplied to you so you can practice situations from the real world. When a CEO gives you a task you need to extrapolate the important pieces of information. You may refer back to practice problem-solving with the Problem Solving Case Study.

Joins

v_art Database:

  1. When you visit the Virtual Art Gallery Database and you search by Period/Style and you choose Impressionism, you get two resulting images ("Woman in the Garden" and "Irises"). What query would be used in the code here to allow the user to see these images? No join is needed. 

    Question 1 Results
    Question 1 Results
  2. When you visit the Virtual Art Gallery Database, search by Subject and type in the word flower, you get three images. What query would have allowed the user to get those results (remember, the keyword might have been 'flowers' but they typed 'flower') .

    Question 2 Results
    Question 2 Results
  3. List all the artists from the artist table, but only the related artwork from the artwork table. We need the first name, last name, and artwork title. 

    Question 3 Results
    Question 3 Results

Magazine Database:

  1. List all subscriptions with the magazine name, last name, first name, and sort alphabetically by magazine name. 

    Question 4 Results
    Question 4 Results
  2. List all the magazines that Samantha Sanders subscribes to. 

    Question 5 Results
    Question 5 Results

Employee Database:

  1. List the first five employees from the Customer Service Department. Put them in alphabetical order by last name.

    Question 6 Results
    Question 6 Results
  2. Find out the current salary and department of Berni Genin. You can use the ORDER BY and LIMIT to get just the most recent salary.

    Question 7 Results
    Question 7 Results

Summary Queries

Using the bike database:

  1. Get the average quantity that we have in all our bike stocks. Round to the nearest whole number. 

    Question 8 Results
    Question 8 Results
  2. Show each bike that needs to be reordered. Filter the results to only the lowest quantity of zero. Order by product_name The image below show the first 12 of 24 rows total. You don't need to use a LIMIT.  (Hint for this one: Two different stores have the same bike that needs to be reordered. You only need it to show up once.)

    Question 9 Results
    Question 9 Results
  3. How many of each category of bikes do we have in stock (inventory) at our "Baldwin Bikes" store, which has the store_id of 2. We need to see the name of the category as well as the number of bikes we have in inventory in the category. Sort by lowest inventory items first. 

    Question 10 Results
    Question 10 Results

Use the employee database to answer the following:

  1. How many employees do we have? (3 points)

    Question 11 Results
    Question 11 Results
  2. Get the average salaries in each department. We only need those departments that have average salaries that are below 60,000. Format the salary to 2 decimal places and a comma in the thousands place. 

    Question 12 Results
    Question 12 Results
  3. Find out how many females work in each department. Sort by department name.

    Question 13 Results
    Question 13 Results

Submission

Upload a single SQL workbench file containing your SQL commands. Make sure you use comments to identity the question number at the start of each statement.

Useful Links: