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...
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...
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...
Using MYSQL in terminal, create the tables for your above designed relational schema and populate your...
Using MYSQL in terminal, create the tables for your above designed relational schema and populate your tables with appropriate data. All except time slot and the relationship it participates in. Use the names for the tables and attributes from the ER schema. Use ON DELETE CASCADE for foreign keys. Each basic table (corresponding to an entity in the ER schema developed for Part 1) should have 5-10 rows. Campus can have just 2. Building should have at least 6. At...
The schema for the Academics database is as follows. Understanding this schema is necessary to answer...
The schema for the Academics database is as follows. Understanding this schema is necessary to answer the questions in Part B. DEPARTMENT(deptnum, descrip, instname, deptname, state, postcode) ACADEMIC(acnum, deptnum*, famname, givename, initials, title) PAPER(panum, title) AUTHOR(panum*, acnum*) FIELD(fieldnum, id, title) INTEREST(fieldnum*, acnum*, descrip) The semantics of most attributes are self-explanatory. For each relation, the primary key is underlined and any foreign keys are denoted by an asterisk (*). Some additional information for relations is given below: DEPARTMENT: Each academic department...
Using WORKBENCH: 1. Create the database below via an ER Diagram in Workbench (take screen shots...
Using WORKBENCH: 1. Create the database below via an ER Diagram in Workbench (take screen shots of the diagram) 2. Go to the database table view and take a screen shot of the table(s) 3. Go to the data entry tool and enter at least three lines of data (in each table). Take screen shots. Create a database that is in third normal form for the following: You are a nerd and have decided to organize your comic books in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT