Question

In: Computer Science

7. Using the provided schema of a Purchase Order Administration database, write the following queries in...

7. Using the provided schema of a Purchase Order Administration database, write the following queries in SQL.

(In the schema, bold attributes are primary keys and italicized attributes are foreign keys.)

SUPPLIER (SUPNR, SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS)

SUPPLIES (SUPNR, PRODNR, PURCHASE_PRICE, DELIV_PERIOD)

PRODUCT (PRODNR, PRODNAME, PRODTYPE, AVAILABLE_QUANTITY)

PO_LINE (PONR, PRODNR, QUANTITY)

PURCHASE_ORDER (PONR, PODATE, SUPNR)

7d) Write a nested SQL query to retrieve the supplier number, supplier name, and supplier status of each supplier who has a higher supplier status than supplier number 21.

7e) Write a nested SQL query using the keyword IN to retrieve the supplier name of each supplier who supplies more than five products.

7f) Write an SQL query that retrieves all pairs of suppliers who supply the same product, along with their product purchase price if applicable.

7g) Create a view, SUPPLIEROVERVIEW, which retrieves for each supplier the supplier number, the supplier name, and the total quantities ordered. Once created, query this view to retrieve suppliers for which the total ordered quantity exceeds 30.

Solutions

Expert Solution

Answer of

7d) Write a nested SQL query to retrieve the supplier number, supplier name, and supplier status of each supplier who has a higher supplier status than supplier number 21.

query - SELECT S1.SUPNR, S1.SUPNAME, S1.SUPSTATUS FROM SUPPLIER S1, SUPPLIER S2 WHERE S1.SUPSTATUS  > S2.SUPSTATUS  AND S2.SUPNR = 21;

Answer of

7e) Write a nested SQL query using the keyword IN to retrieve the supplier name of each supplier who supplies more than five products.

query - SELECT SUPNAME FROM SUPPLIER WHERE SUPNR IN (SELECT SUPNR FROM PURCHASE_ORDER WHERE COUNT(PONR) > 5 GROUP BY SUPNR )

Answer of

7f) Write an SQL query that retrieves all pairs of suppliers who supply the same product, along with their product purchase price if applicable.

query -

SELECT P.PRODNR, P.PRODNAME, S1.SUPNR, S1.SUPNAME, S.PURCHASE_PRICE

FROM PRODUCT P, SUPPLIES S, SUPPLIER S1

WHERE S.PRODNR IN (SELECT PRODNR FROM SUPPLIES WHERE COUNT(SUPNR) > 1 GROUP BY PRODNR) AND S1.SUPNR = S.SUPNR AND P.PRODNR = S.PRODNR;

Answer of

7g) Create a view, SUPPLIEROVERVIEW, which retrieves for each supplier the supplier number, the supplier name, and the total quantities ordered. Once created, query this view to retrieve suppliers for which the total ordered quantity exceeds 30.

query -

First create view

CREATE VIEW [SUPPLIEROVERVIEW] AS

SELECT S1.SUPNR, S1.SUPNAME, SUM(PO.QUANTITY) AS TOTQTY

FROM SUPPLIER S1, PO_LINE PO, PURCHASE_ORDER PR

WHERE PR.SUPNR = S1.SUPNR AND PR.PONR= PO.PONR GROUP BY PO.PONR;

query this view to retrieve suppliers for which the total ordered quantity exceeds 30.

SELECT * FROM SUPPLIEROVERVIEW WHERE TOTQTY > 30;


Related Solutions

Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a...
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a select statement to show the invoicelineitemdescriptions that have the total invoicelineitemamount >1000 and the number of accountno is >2. 10. Write a select statement that returns the vendorid, paymentsum of each vendor, and the number of invoices of each vendor, where paymentsum is the sum of the paymentotal column. Return only the top ten vendors who have been paid the most and the number...
Write the following queries using the schema below Class (Number, Department, Term, Title) Student (Username, FirstName,...
Write the following queries using the schema below Class (Number, Department, Term, Title) Student (Username, FirstName, LastName, Year) Takes (Username, Department, Number, Term, Grade) [clarification] In Student, Year is an integer. A student can be a 2nd year student. In that case, Year value would be 2. For the Takes relation: ·         Grade is NA for current semester students ·         Username is foreign key to Student ·         (Department, Number, Term) is foreign key to Class a)       Write an SQL query that returns the Term...
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...
Write SQL queries for the following statements based on Employees table whose schema is given below:...
Write SQL queries for the following statements based on Employees table whose schema is given below: (Employee_ID,First_Name,Last_Name,Email,Phone_Number,Hire_Date,Job_ID,Salary, Manager_Id, Department_Id) a. Create the given table along with the following constraints: Phone_Number should not be left undefined, salary should be between 10000 and 20000, employee_id should uniquely identify rows and should not be left undefined. User-defined names should be given to constraints. b.  Display each employee’s last name, hire date and salary review date (which is the date after six months of service)....
Basic SQL Use the following schema to answer the queries below using SQL DEVICE [dno, dtype,...
Basic SQL Use the following schema to answer the queries below using SQL DEVICE [dno, dtype, price] PROVIDER [pno, pname, web] SERVICE [dno, pno, servicedate] SERVICE.dno references DEVICE.dno SERVICE.pno references PROVIDER.pno bold is underline. a) Find the dno for the most expensive device b) Find all providers that have the work fast in the name c) Find the number of different device types (dtype) d) Give all details of devices with price more than $400
Instructions: Complete the following queries using the Colonial Adventure Tours database. You will find the description...
Instructions: Complete the following queries using the Colonial Adventure Tours database. You will find the description including data of this database in page 16 to page 20 in Chapter 1 in your Concepts of Database Management textbook. For each following question, create a query using the Query Design option in Access. Make sure that you save and name each query in the following manner: Query1, Query2......Query14. Query Questions: Queries: 1. List the name of each trip that does not start...
Create the following SQL queries using the lyrics database below 1. List the first name, last...
Create the following SQL queries using the lyrics database below 1. List the first name, last name, and region of members who do not have an email. 2. List the first name, last name, and region of members who do not have an email and they either have a homephone ending with a 2 or a 3. 3. List the number of track titles that begin with the letter 's' and the average length of these tracks in seconds 4....
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...
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...
Please write queries based on the following requirements using labdata.sql. For each question, you are required...
Please write queries based on the following requirements using labdata.sql. For each question, you are required to submit 1) SQL query code; 2) a screen shot of your query result. You should copy and paste your SQL query code to the word document instead of taking a screenshot of your code. Missing either part for each question will result in 0 for this question. List all the order date and the number of orders placed on each date. Rank your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT