Question

In: Computer Science

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:

  1. Select the name of each manufacturer along with the name and price of its most expensive product.

  2. Computer products are expensive. Find the maximum priced product. Which products are within $30 of the maximum priced product.

  3. 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 varchar(50) NOT NULL
);

CREATE TABLE products (
code NUMBER PRIMARY KEY NOT NULL,
name varchar(50) NOT NULL ,
price real NOT NULL ,
manufacturer number NOT NULL
CONSTRAINT fk_manufacturers_code REFERENCES manufacturers(code)
);

INSERT INTO manufacturers(code,name) VALUES(1,'Sony');
INSERT INTO manufacturers(code,name) VALUES(2,'Creative Labs');
INSERT INTO manufacturers(code,name) VALUES(3,'Hewlett-Packard');
INSERT INTO manufacturers(code,name) VALUES(4,'Iomega');
INSERT INTO manufacturers(code,name) VALUES(5,'Fujitsu');
INSERT INTO manufacturers(code,name) VALUES(6,'Winchester');

INSERT INTO products(code,name,price,manufacturer) VALUES(1,'Hard drive',240,5);
INSERT INTO products(code,name,price,manufacturer) VALUES(2,'Memory',120,6);
INSERT INTO products(code,name,price,manufacturer) VALUES(3,'ZIP drive',150,4);
INSERT INTO products(code,name,price,manufacturer) VALUES(4,'Floppy disk',5,6);
INSERT INTO products(code,name,price,manufacturer) VALUES(5,'Monitor',240,1);
INSERT INTO products(code,name,price,manufacturer) VALUES(6,'DVD drive',180,2);
INSERT INTO products(code,name,price,manufacturer) VALUES(7,'CD drive',90,2);
INSERT INTO products(code,name,price,manufacturer) VALUES(8,'Printer',270,3);
INSERT INTO products(code,name,price,manufacturer) VALUES(9,'Toner cartridge',66,3);
INSERT INTO products(code,name,price,manufacturer) VALUES(10,'DVD burner',180,2);

Solutions

Expert Solution

Select the name of each manufacturer along with the name and price of its most expensive product.

select m.name, p.name, max(p.price)
from manufacturers as m, products as p
where m.code=p.code;

Explanation: This query will fetch records from manufaturers and products tables where manufacturers code matches with product code.

Find the maximum priced product.

select name, max(price)
from products;

Explanation: we will use max operator in sql to fetch maximum priced product from products table.

Which products are within $30 of the maximum priced product.

select name, price
from products
where price between 30 and 270;

Explanation : Between operator will specify the products whose price lies between 30 and 270.

Find the maker of the most expensive ‘drive’.

select m.name ,p.name, max(p.price)
from manufacturers as m, products as p
where m.code=p.code and p.name LIKE '%drive';

Explanation: Firstly we need to match manhufacture and product code to fetch the details of maker. for getting maximum priced item use max operator and to match the drive name use LIKE operator.


Related Solutions

For each exercise, answer the following along with any additional questions.  Select and justify the...
For each exercise, answer the following along with any additional questions.  Select and justify the best test(s). The chi-square, Phi, Yates, or Lambda (or even a combination) might be best for a problem given the data and research question. Do not assume the independent is always on the row.  Provide the null and alternative hypotheses in formal and plain language for the appropriate test at the 0.05 significance level.  Do the math and reject/retain null at a=.05....
For each exercise, answer the following along with any additional questions.  Select and justify the...
For each exercise, answer the following along with any additional questions.  Select and justify the best test(s). The chi-square, Phi, Yates, or Lambda (or even a combination) might be best for a problem given the data and research question. Do not assume the independent is always on the row.  Provide the null and alternative hypotheses in formal and plain language for the appropriate test at the 0.05 significance level.  Do the math and reject/retain null at a=.05....
Write a query to display the columns listed below. For each customer the query should show...
Write a query to display the columns listed below. For each customer the query should show the current system date, the current day (when you do the problem the date and day will be different), the number of characters in the member last name, the last date the customer rented a video and how many total videos the person rented. /* Database Systems, 9th Ed., Coronel/MOrris/Rob */ /* Type of SQL : MySQL */ CREATE SCHEMA IF NOT EXISTS TINY_VIDEO;...
1. How do I write a query that displays the name (concatenate the first name, middle...
1. How do I write a query that displays the name (concatenate the first name, middle initial, and last name), date of birth, and age for all students? Show the age with no decimal places, and only include those students who are 21 or older. Order by age, as shown below: (Hint: Use the TRUNC function. The ages may be different, depending on the date that the query is run.) SELECT S_FIRST || ' ' || S_MI || ' '...
Please select all of the correct statements about hemolytic disease of the newborn. Another name for...
Please select all of the correct statements about hemolytic disease of the newborn. Another name for hemolytic disease of the newborn is erythroblastosis fetalis. Hemolytic disease of the newborn may result if an Rh– mother is carrying an Rh+ fetus. Hemolytic disease of the newborn can be prevented by giving the newborn passive immunization with RhoGAM. There is not a risk of hemolytic disease of the newborn if both parents are Rh–. Hemolytic disease of the newborn is more likely...
Please answer the following questions: Select the correct option: Acceptable depreciation methods under IFRS include a....
Please answer the following questions: Select the correct option: Acceptable depreciation methods under IFRS include a. Straight-line. b. Accelerated. c. Units-of-production. d. All of the above. 2. The activity method of depreciation a. is a variable charge approach. b. assumes that depreciation is a function of the passage of time. c. conceptually associates cost in terms of input measures. d. all of these. 3. In measuring an impairment loss, IFRS uses a. undiscounted cash flows b. discounted cash flows c....
PLEASE explain why each answer of the following questions is correct, I need to understand it...
PLEASE explain why each answer of the following questions is correct, I need to understand it . 1)Economy is at its long run equilibrium. Assuming all else equal, stock market collapses and consumer sentiment level deteriorates. Which of the following is incorrect? A. In short run, output level decreases and price level decreases. B. In long run, output level is back to its long run output level. C. In short run, short run aggregate supply decrease. D. In long run,...
Write the correct chemical formula for each of the following.
Write the correct chemical formula for each of the following. a) Calcium sulfate trihydrate b) Sulfide ion c) Nitrogen dioxide d) Lead (IV) hypochlorite e) Ammonium sulfite f) Barium chloride g) sodium hydride h) sulfur trioxide i) sulfite ion
1. Write a query to: a. select data from INVOICES table as follows: Invoice date in...
1. Write a query to: a. select data from INVOICES table as follows: Invoice date in MM/DD/YYYY format Invoice Date in DD-Mon-YYYY format Invoice Total rounded to the nearest dollar Note: you can alias columns as you sit fit b. select data from VENDORS table as follows: Vendor Name Concatenate Vendor Name with the string ‘s Address Concatenate Vendor City, Vendor State and Vendor Zip Code (alias this) Your output should look like this (this is just an example of...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT