0% found this document useful (0 votes)
2 views

0801EC211080_DBMS_Assignment4

The document contains SQL commands for creating and manipulating database tables for manufacturers and products. It includes commands for creating tables, inserting data, and various queries to retrieve product information based on specific criteria. Additionally, it covers updates and discounts applied to product prices.

Uploaded by

yash
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

0801EC211080_DBMS_Assignment4

The document contains SQL commands for creating and manipulating database tables for manufacturers and products. It includes commands for creating tables, inserting data, and various queries to retrieve product information based on specific criteria. Additionally, it covers updates and discounts applied to product prices.

Uploaded by

yash
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

0801EC211080

Tanish Jain

ASSIGNMENT - 4

Q. Create tables.

Sol.
CREATE TABLE manufacturer
(code int primanry key auto_increment,name char(20) not NULL);

CREATE TABLE products


(code int primanry key,name char(20) not NULL,price decimal(10,2) not
NULL,manufacturer int not NULL,foreign key (manufacturer) REFERENCES
manufacturer(code));

Q. Insert into tables.


0801EC211080
Tanish Jain

Sol.
insert into manufacturer (code,name) VALUES
(1, 'Sony'),
(2, 'Creative Labs'),
(3, 'Hewlett-Packard'),
(4, 'Iomega'),
(5, 'Fujitsu'),
(6, 'Winchester');

insert into products (code,name,price,manufacturer) VALUES


(1, 'Hard Drive', 240, 5),
(2, 'Memory', 120, 6),
(3, 'Zip Drive', 150, 4),
(4, 'Floppy Disk', 5, 6),
(5, 'Monitor', 240, 1),
(6, 'DVD Drive', 180, 2),
(7, 'CD Drive', 90, 2),
(8, 'Printer', 270, 3),
(9, 'Tone Cartridge', 66, 3),
(10, 'DVD Burner', 180, 2);

1. Select the names of all product in the store.


Sol. SELECT (name) FROM products;
0801EC211080
Tanish Jain

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

5. Select name and price in cents(i.e. the price multiply by 100).


Sol. SELECT name,price*100 as “Price in cents” from products;

6. Compute the average price of all the product.


Sol. select avg(price) from products;

7. Compute average price of all products with manufacturer code equal to 2.


Sol. select avg(price) from products where manufacturer='2';

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

15. Select the name and price of the cheapest product.

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;

17. Add a new product: Loudspeakers, $70, Manufacturer 2.


Sol. insert into products values('Loudspeakers',70,2);

18. Update the name of product 8 to “Laser printer”.


Sol. update products set name='Laser printer' where code='8';

19. Apply a 10% discount to all products.


Sol. select name,price*0.9 as "Price with 10% discount" from products
0801EC211080
Tanish Jain

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;

You might also like