Question

In: Computer Science

1.Write an SQL query that retrieves all pairs of suppliers who supply the same product, along...

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

2.Create a view SUPPLIEROVERVIEW that retrieves, for each supplier, the supplier number, the supplier name, and the total amount of quantities ordered. Once created, query this view to retrieve suppliers for whom the total ordered quantity exceeds 30.

3.Write a nested SQL query to retrieve all purchase order numbers of purchase orders that contain either sparkling or red wine.

Solutions

Expert Solution

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

select sr.supnr as "Supplier No.",sr.supname as "Supplier Name", p.prodnr as "Product No.", p.prodname as "Product Name",s.purchase_price as "Purchase Price" from supplier as sr,supplies as s,product as p where sr.supnr=s.supnr and s.prodnr=p.prodnr and p.prodnr in(select s1.prodnr from supplies as s1 group by s1.prodnr having COUNT(s1.supnr) > 1)

2. Create a view SUPPLIEROVERVIEW that retrieves, for each supplier, the supplier number, the supplier name, and the total amount of quantities ordered. Once created, query this view to retrieve suppliers for whom the total ordered quantity exceeds 30.

create view SUPPLIEROVERVIEW as select sr.supnr as "supplier_no",sr.supname as "supplier_name",sum(pol.quantity) as "total_quantity" from supplier as sr,supplies as s,product as p,po_line as pol where sr.supnr=s.supnr and s.prodnr=p.prodnr and p.prodnr=pol.prodnr group by sr.supnr;
select supplier_no,supplier_name from SUPPLIEROVERVIEW where total_quantity > 30

3. Write a nested SQL query to retrieve all purchase order numbers of purchase orders that contain either sparkling or red wine.

select po.ponr as "Purchase Order No." from purchase_order as po,po_line as pol,product as p where p.prodnr=pol.prodnr and pol.ponr=po.ponr and p.prodnr in(select pr.prodnr from product as pr where pr.prodname in('sparkling','red wine'))

Related Solutions

1. Write a query in SQL to find the full name of the “Actors” who appeared...
1. Write a query in SQL to find the full name of the “Actors” who appeared in the movie titled Star Wars (using JOIN ). 2.Write a SQL query to find the movie Title that has received Lowest rating from reviewers, but whose actors have received an award for their contribution in movie. (Expected Output: Fantastic Beasts and Where to Find Them) 3.Write a SQL query that display the list of genres, Number of movies in that genre grouped by...
write a sql statement that retrieves product ID (ProductID) and name (Name) from Production.product table for...
write a sql statement that retrieves product ID (ProductID) and name (Name) from Production.product table for all product whose name includes both the words "silver" and "frame"
In sql: Write a query to produce a listing of unique vendor names who have at...
In sql: Write a query to produce a listing of unique vendor names who have at least one invoice with us. You are using a table view called COMPANY_INFORMATION that lists a vendor id, vendor name, term id, and term description. The second table you will reference is the invoice table that lists vendor id, invoice num, invoice number, and invoice total. Do not show duplicate results.
How to write a query in SQL using the Group by function to decide if the...
How to write a query in SQL using the Group by function to decide if the results of the diet worked. There are 6 columns ID, Gender, treatment, start_weight_kg, end_weight_kg, and correct change (end weight minus start weight). With the information given write a SQL to determine if the the results(correct change) worked. Question is not incomplete.
Develop SQL statements to do the following: Query 1: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_EMP_CITY,...
Develop SQL statements to do the following: Query 1: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_EMP_CITY, LXXX_EMP_PHONE, LXXX_DEP_ID, order by LXXX_DEP_ID. Query 2: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_DEP_NAME, order by LXXX_DEP_NAME. Query 3: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_DEP_NAME who work for the "XXX_SALES" department. Query 4: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_DEP_NAME, LXXX_EMP_CITY, LXXX_DEP_CITY who live and work in the same city, order by LXXX_DEP_CITY Query 5: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_PROJ_TYPE, LXXX_START_DATE,...
SQL query exercises: Consider the following database schema:                Product(maker, model, type)              &
SQL query exercises: Consider the following database schema:                Product(maker, model, type)                PC(model, speed, ram, hd, rd, price)                Laptop(model, speed, ram, hd, screen, price)                Printer(model, color, type, price) Consider the Drivers-Cars-Reserves DB for a small rental car company:                Drivers(id, name, rating, age)                Cars(vin, maker, model, year, color)                Reserves(did, vin, date) Give SQL statement each of the following operations: Find the colors of cars reserved by Smith. Find all id’s of drivers who have a...
5. Write the SQL query that accomplishes the task in the ZAGI Retail Company Sales Department...
5. Write the SQL query that accomplishes the task in the ZAGI Retail Company Sales Department Database: 5.1.3. Display the CustomerName and CustomerZip for all customers, sort alphabetically by CustomerName. 5.1.4. Display the RegionID of regions where we have stores (use only table STORES and do not display the same information more than once). 5.1.5 Display all the information for all stores whose ReigionID value is C 5.1.8 Display the ProductID, ProductName, ProductPrice, and VendorName for all products. Sort the...
Write an SQL query that will output the employee id, first name and hire date from...
Write an SQL query that will output the employee id, first name and hire date from the employee table. Pick only those employees whose employee ID is specified in the employee table (no nulls). If the employee id is 777, name is ABC and hire date is 01-JAN-2016, the output should be like - ' ABC (Employee ID - 777) was hired on 1, January of 2016'. Note - The date should not have preceding zeros.
Write a SQL query that displays the number of customers from Mexico, USA, and Canada. Hint:...
Write a SQL query that displays the number of customers from Mexico, USA, and Canada. Hint: The result of the SQL query should look like the following table: CustomerCountNorthAmerica 21
Question: Write a single SQL query that, for each pair of actors, lists their two actor_ids...
Question: Write a single SQL query that, for each pair of actors, lists their two actor_ids and the number of films in which both actors appeared. DATABASE SCHEMA CREATE TABLE actor ( actor_id INTEGER, first_name TEXT, last_name TEXT); CREATE TABLE film ( film_id INTEGER, title TEXT, description TEXT, length INTEGER); CREATE TABLE film_actor ( actor_id INTEGER, film_id INTEGER);
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT