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...
I am having trouble writing these queries in MYSQL. Using the schema listed below, please write...
I am having trouble writing these queries in MYSQL. Using the schema listed below, please write the following queries in MYSQL: 1) Find the Content and the Reviewer Name for each comment, about “ACADEMY DINOSAUR” only if the same reviewer has commented about “ACE GOLDFINGER” too. 2) Retrieve the title of all the Movies in Japanese without any comment, ordered alphabetically. 3) Find all the movie titles where an actor called “TOM” or an actor called “BEN" acted, where there...
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...
Question 2: consider the following library relational database schema Write a program segment to retrieves the...
Question 2: consider the following library relational database schema Write a program segment to retrieves the list of books that became overdue yesterday and that prints the book title and borrower name for each. 1- Use JDBC with Java as the host language
) Write queries for the following. Include screenshots of the queries and the outputs. Create a...
) Write queries for the following. Include screenshots of the queries and the outputs. Create a procedure named DisplayInfo which takes customer name as a parameter and displays information of that customer. (database – sql_store)
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....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT