Question

In: Computer Science

This refer to the “om” database (or Schema) that you will find in your MySQL Workbench...

This refer to the “om” database (or Schema) that you will find in your MySQL Workbench program if you have run the sample database install script.

Please save all of your answers in one script (.sql) or type all your answers into Notepad++ and submit them as a single .sql file. Please test your SQL statements in Workbench

1.       Using an INNER JOIN, select the order_id, order_date, shipped_date, fname, and customer_phone from the orders and customers tables. The fname is a column alias and should be formatted as “Smith, John” (last name, first name). Result table should be in order of order_id in ascending order.

2.       Write a SELECT statement that returns these columns using a JOIN of three tables:

a.       order_date from the orders table

b.       shipped_date from the orders table

c.       order_qty from the order_details table

d.       title from the items table

e.       artist from the items table

f.        unit_price from the items table

g.       Result table should be in order of order_date in ascending order

3.       Expand the SELECT statement from the previous question to include the customer last name and first initial from the customers table. The name should be formatted as “Lastname, F.” and given the column alias cname.

Order table is making by yourself. Please do as soon as possible. Please use the tidy tools for SQL proper format.

Solutions

Expert Solution

Solution:

SQL queries have been given below.

Kindly let me know if you require additional information.

Hope that helps.

Query 1 - Will give the required columns by using the INNER JOIN. (syntax has been validated)

The column names for 'firstname' and 'lastname' have been assumed, in case they are existing as a different column names in the table, kindly replace the text c.lastname, ", ", c.firstname - with the column names from database table.

select
  o.order_id,
  o.order_date,
  o.shipped_date,
  CONCAT(c.lastname, ", ", c.firstname) as fname,
  c.customer_phone
from
  Customers c
  INNER JOIN Orders o on c.Customer_id = o.Customer_id
Order by
  o.order_id

Query 2 : it has been assumed that there is a column item_id, which is primary key of items table and a foreign key in the order_details table. In case the column name is known by a different name in the database, kindly replace the item_id by actual column name.

Select
  o.order_date,
  o.shipped_date,
  od.order_qty,
  i.title,
  i.artist,
  i.unit_price
From
  orders o
  INNER JOIN order_details od on o.order_id = od.order_id
  INNER JOIN items i on od.item_id = i.item_id
order by
  o.order_date

Query 3

Select
  o.order_date,
  o.shipped_date,
  od.order_qty,
  i.title,
  i.artist,
  i.unit_price,
  CONCAT(
    c.lastname,
    ", ",
    SUBSTRING(c.firstname, 1, 1),
    "."
  ) as cname
from
  Customers c
  INNER JOIN Orders o on c.Customer_id = o.Customer_id
  INNER JOIN order_details od on o.order_id = od.order_id
  INNER JOIN items i on od.item_id = i.item_id
order by
  o.order_date

Related Solutions

All questions in this assignment refer to the “om” database (or Schema) that you will find...
All questions in this assignment refer to the “om” database (or Schema) that you will find in your MySQL Workbench program if you have run the sample database install script. Please save all of your answers in one script (.sql) or type all your answers into Notepad++ and submit them as a single .sql file. You are encouraged to test your SQL statements in Workbench, and please use the ‘tidy’ tool to properly format your SQL before you save it...
This assignment refer to the “om” database (or Schema).      1.Write an INSERT statement that adds this...
This assignment refer to the “om” database (or Schema).      1.Write an INSERT statement that adds this row to the Items table:   a.       Artist:               Newly Added b.       Title:                      Assignment 3 c.        unit_price:         0.0 d.       ID:                          12 2.       Write an UPDATE statement that modifies the row you just added to the Items table. This statement should change the artist column to “RockOn”, and it should use the ID column to identify the row.    3.       Write a DELETE statement that deletes the row you...
In MySql, using Application MYSQL Workbench and the Chinook database, please answer the following: -- 12....
In MySql, using Application MYSQL Workbench and the Chinook database, please answer the following: -- 12. SELECT the trackid, name and filesize (as shown in the bytes column) for all tracks that have a file size less than 2000000 and a GenreId of 1 or a file size less than 2000000 and a Genreid of 2 -- 13. Add a sort to the query from number 12 to sort by GenreID; -- 14. List all columns from the customer table...
Using the world_x database you installed on your MySQL Workbench, create a new table named “independence”...
Using the world_x database you installed on your MySQL Workbench, create a new table named “independence” with the following attributes (columns): A field named “id” which has data type auto_increment, A field named “country_name” which has data type varchar(50), and A field named “independence_date” which has type “date.” After you create the table, run the following SQL command: INSERT INTO independence(country_name, independence_date) VALUE (‘United States’,’1776-07-04’) Submit a 1-page Microsoft Word document that shows the following: The SQL command you used...
Part 2: Use MySQL Workbench to add a table to your database on the class server...
Part 2: Use MySQL Workbench to add a table to your database on the class server and name the table “Person”. Include these fields in the Person table: Field Name Description Data Type Sample Value LoginID User’s login name varchar(10) Bob FirstName User’s first name varchar(50) Bob LastName User’s last name varchar(50) Barker picUrl Filename of the user’s picture varchar(50) bob.gif Bio User’s biography varchar(255) Bob is the best! LoginID should be the Primary Key of the table. Add at...
Design and implement a relational database application of your choice using MS Workbench on MySQL a)...
Design and implement a relational database application of your choice using MS Workbench on MySQL a) Declare two relations (tables) using the SQL DDL. To each relation name, add the last 4 digits of your Student-ID. Each relation (table) should have at least 4 attributes. Insert data to both relations (tables); (15%) b) Based on your expected use of the database, choose some of the attributes of each relation as your primary keys (indexes). To each Primary Key name, add...
This is in MySQL Part one: Using the MySQL Workbench Data Modeler, construct a diagram that...
This is in MySQL Part one: Using the MySQL Workbench Data Modeler, construct a diagram that shows the table in 3rd Normal Form. Part two: Provide a summary of the steps you took to achieve 3rd Normal form. Include your rationale for new table creation, key selection and grouping of attributes. Table Details: The Anita Wooten Art Gallery wishes to maintain data on their customers, artists and paintings. They may have several paintings by each artist in the gallery at...
using the lyrics database schema in mysql provided below. 1.)List the artist name of the artists...
using the lyrics database schema in mysql provided below. 1.)List the artist name of the artists who do not have a webaddress and their leadsource is “Directmail”? 2.)List the names of members in the artist called 'Today'. 3.)Report the total runtime in minutes FOR EACH album in the Titles table. 4.)List the firstname, lastname of members who are represented by the salesperson “Lisa Williams” 5.)List EACH salesperson’s firstname along with the number of Members that EACH SalesPerson represents. below is...
using mysql and the schema is provided below. thanks In this lab, you will be manipulating...
using mysql and the schema is provided below. thanks In this lab, you will be manipulating the database to add, delete and modify the values in the database. Please use a "select * from..." after each query to show the effects of your data manipulation query. 1. The title 'Time Flies' now has a new track, the 11th track 'Spring', which is 150 seconds long and has only a MP3 file. Insert the new track into Tracks table (Don’t hand-code...
We use the WMCRM database and here is the summary of the database schema (where schema...
We use the WMCRM database and here is the summary of the database schema (where schema is used in its meaning of a summary of the database structure): VEHICLE (InventoryID, Model, VIN) SALESPERSON (NickName, LastName, FirstName, HireDate, WageRate, CommissionRate, OfficePhone, EmailAddress, InventoryID) CUSTOMER (CustomerID, LastName, FirstName, Address, City, State, ZIP, EmailAddress, NickName) PHONE_NUMBER (CustomerID, PhoneNumber, PhoneType) CONTACT(ContactID, CustomerID,ContactDate,ContactType,Remarks) Where InventoryID in SALESPERSON must exist in InventoryID in VEHICLE NickName in CUSTOMER must exist in NickName in SALESPERSON CustomerID in PHONE_NUMBER...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT