0801EC211080_DBMS_Assignment4
0801EC211080_DBMS_Assignment4
Tanish Jain
ASSIGNMENT - 4
Q. Create tables.
Sol.
CREATE TABLE manufacturer
(code int primanry key auto_increment,name char(20) not NULL);
Sol.
insert into manufacturer (code,name) VALUES
(1, 'Sony'),
(2, 'Creative Labs'),
(3, 'Hewlett-Packard'),
(4, 'Iomega'),
(5, 'Fujitsu'),
(6, 'Winchester');
2. Select the names and the prices of all the products in the store.
Sol. SELECT name,price from products;
3. Select the name of products with price less than or equal to $200.
Sol. select name from products where price<='200';
4. Select all the products with a price between $60 and $120.
Sol. SELECT name from products where price>60 AND price<120;
0801EC211080
Tanish Jain
8. Compute the number of products with a price larger then or equal to $180.
Sol. select count(*) from products where price>='180';
9. Select the name and price of all products with a price larger then or equal to $180
and, sort first by price (in descending order), and then by name(in ascending order).
Sol. select name,price from products where price>=180 order by price desc,name;
0801EC211080
Tanish Jain
10. Select all the data from products, including all the data for each products
manufacturer.
Sol. select * from products join manufacturer on products.manufacturer=manufacturer.code;
11. Select the product name, Price , and manufacturer names of all products.
Sol. select products.name,products.price,manufacturer.name from products join
manufacturer on products.manufacturer=manufacturer.code;
0801EC211080
Tanish Jain
12. Select the average price of each manufacturers products, showing only the
manufacturer code.
Sol. select manufacturer.code,avg(products.price) from manufacturer
join products on manufacturer.code=products.manufacturer
GROUP by manufacturer.code;
13. Select the average price of each manufacturers products, Showing the
manufacturers name.
Sol. select manufacturer.name,avg(products.price) from manufacturer join products on
manufacturer.code=products.manufacturer GROUP by manufacturer.code;
0801EC211080
Tanish Jain
14. Select the name of manufacturers whose product have an average price larger than
or equal to $150.
Sol. SELECT manufacturer.name,avg(products.price) from manufacturer
join products on manufacturer.code=products.manufacturer
group by manufacturer.code
HAVING avg(products.price)>150
Sol.
16. Select the name of each manufacturer along with the name and price of its most
expensive product.
Sol. select manufacturer.name,products.name,max(products.price) from manufacturer join
products on manufacturer.code=products.manufacturer group by manufacturer.code;
20. Apply a 10% discount to all products with a price larger than or equal to $120.
Sol. select name,price*0.9 as "Price with 10% discount" from products where price>120;