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

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.
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 a SQL query to find the movie Title that has received Lowest rating from reviewers,...
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. Output: Fantastic Beasts and Where to Find Them            //   THE DATABASE // DROP DATABASE IF EXISTS cs431_movie_database; CREATE DATABASE cs431_movie_database; USE cs431_movie_database; CREATE TABLE `artists` ( `artist_id` INT NOT NULL AUTO_INCREMENT, `first_name` varchar(45) NOT NULL, `last_name` varchar(45) NOT NULL, `contact_no` varchar(15) DEFAULT NULL, `Profession` TEXT DEFAULT NULL, `birth_date` datetime DEFAULT NULL,...
1. How do indexes improve SQL query performance? 2. How can stored procedure design improve query...
1. How do indexes improve SQL query performance? 2. How can stored procedure design improve query times in a data mart? 3. Why/How does de-normalization of a data mart design improve performance of queries? 4. What is a different between Client-Servervs. Distributed Architecture? 5. What are some primary features of a 3-tier architecture design?
Please write the correct query for the following questions: Select the name of each manufacturer along...
Please write the correct query for the following questions: Select the name of each manufacturer along with the name and price of its most expensive product. Computer products are expensive. Find the maximum priced product. Which products are within $30 of the maximum priced product. Find the maker of the most expensive ‘drive’. Note, there are variety of drives in the data. Regular expressions help. Using the following table: CREATE TABLE manufacturers ( code number PRIMARY KEY NOT NULL, name...
Product that will burden suppliers (inelastic supply) Factors Supportive Argument 1. 2. 3.
Product that will burden suppliers (inelastic supply) Factors Supportive Argument 1. 2. 3.
The Demand and Supply model typically assumes A- All sellers offer pretty much the same product...
The Demand and Supply model typically assumes A- All sellers offer pretty much the same product and both buyers andsellers accept the market price as outside their individual control. B- None of these. C- All sellers offer pretty much the same product. D- Buyers and sellers accept the market price as outside their individual control Which market is probably the best match for the demand and supply model? A- The world market for coal. B- The Eureka labor market for...
In studies of human MZ and DZ twin pairs of the same sex who are reared...
In studies of human MZ and DZ twin pairs of the same sex who are reared together, the following concordance values are identified for various traits. Based on the values shown, describe the relative importance of genes versus the influence of environmental factors for each trait. Trait Concordance MZ DZ Blood type 100 65 Chicken pox 89 87 Manic depression 67 13 Schizophrenia 72 12 Diabetes 62 15 Cleft lip 51 6 Club foot 40 4
Write SQL queries below for each of the following: List the names and cities of all...
Write SQL queries below for each of the following: List the names and cities of all customers List the different states the vendors come from (unique values only, no duplicates) Find the number of customers in California List product names and category descriptions for all products supplied by vendor Proformance List names of all employees who have sold to customer Rachel Patterson
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT