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

Program 10

The document shows the creation of a Product table with fields No, Product_Name, Brand_Name, Quantity, and Price. It then inserts records for various products, runs queries to select, count, average, and find the maximum price from the table.

Uploaded by

jiciy61793
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Program 10

The document shows the creation of a Product table with fields No, Product_Name, Brand_Name, Quantity, and Price. It then inserts records for various products, runs queries to select, count, average, and find the maximum price from the table.

Uploaded by

jiciy61793
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

mysql> create table Product(No int(10) primary key,Product_Name

varchar(30),Brand_Name varchar(20),Quantity int(10),Price int(10));


Query OK, 0 rows affected, 3 warnings (0.01 sec)

mysql> desc product;


+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| No | int | NO | PRI | NULL | |
| Product_Name | varchar(30) | YES | | NULL | |
| Brand_Name | varchar(20) | YES | | NULL | |
| Quantity | int | YES | | NULL | |
| Price | int | YES | | NULL | |
+--------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> insert into product


-> values(1,'Mixer Grinder','Maharaja',5,1250);
Query OK, 1 row affected (0.05 sec)

mysql> insert into product


-> values(2,'Washing Machine','Whirlpool',10,8500);
Query OK, 1 row affected (0.00 sec)

mysql> insert into product


-> values(3,'Microwave Oven','Phillips',6,8700);
Query OK, 1 row affected (0.00 sec)

mysql> insert into product


-> values(4,'Vaccum Cleaner','Eureka Forbs',2,7400);
Query OK, 1 row affected (0.01 sec)

mysql> insert into product


-> values(5,'Dish Washer','Maharaja',5,12500);
Query OK, 1 row affected (0.01 sec)

mysql> select * from product;


+----+-----------------+--------------+----------+-------+
| No | Product_Name | Brand_Name | Quantity | Price |
+----+-----------------+--------------+----------+-------+
| 1 | Mixer Grinder | Maharaja | 5 | 1250 |
| 2 | Washing Machine | Whirlpool | 10 | 8500 |
| 3 | Microwave Oven | Phillips | 6 | 8700 |
| 4 | Vaccum Cleaner | Eureka Forbs | 2 | 7400 |
| 5 | Dish Washer | Maharaja | 5 | 12500 |
+----+-----------------+--------------+----------+-------+
5 rows in set (0.00 sec)

1. To list the Product_Name where Brand_Name is Maharaja.

mysql> select Product_Name from product where Brand_Name='Maharaja';


+---------------+
| Product_Name |
+---------------+
| Mixer Grinder |
| Dish Washer |
+---------------+
2 rows in set (0.00 sec)
2. To display a report Product_Name and Brand_Name and Price in descending order of
Price.

mysql> select Product_Name,Brand_Name,Price from product order by Price desc;


+-----------------+--------------+-------+
| Product_Name | Brand_Name | Price |
+-----------------+--------------+-------+
| Dish Washer | Maharaja | 12500 |
| Microwave Oven | Phillips | 8700 |
| Washing Machine | Whirlpool | 8500 |
| Vaccum Cleaner | Eureka Forbs | 7400 |
| Mixer Grinder | Maharaja | 1250 |
+-----------------+--------------+-------+
5 rows in set (0.00 sec)

3. To count the number of Product_Name.

mysql> select count(Product_Name) from product;


+---------------------+
| count(Product_Name) |
+---------------------+
| 5 |
+---------------------+
1 row in set (0.00 sec)

4. To insert a new row in the table product


6,'Gas Stove','Maharaja',7,6150.

mysql> insert into product


-> values(6,'Gas Stove','Maharaja',7,6150);
Query OK, 1 row affected (0.01 sec)

mysql> select * from product;


+----+-----------------+--------------+----------+-------+
| No | Product_Name | Brand_Name | Quantity | Price |
+----+-----------------+--------------+----------+-------+
| 1 | Mixer Grinder | Maharaja | 5 | 1250 |
| 2 | Washing Machine | Whirlpool | 10 | 8500 |
| 3 | Microwave Oven | Phillips | 6 | 8700 |
| 4 | Vaccum Cleaner | Eureka Forbs | 2 | 7400 |
| 5 | Dish Washer | Maharaja | 5 | 12500 |
| 6 | Gas Stove | Maharaja | 7 | 6150 |
+----+-----------------+--------------+----------+-------+
6 rows in set (0.00 sec)

5. Select avg(Price) from product where Brand_Name='Maharaja';

mysql> Select avg(Price) from product where Brand_Name='Maharaja';


+------------+
| avg(Price) |
+------------+
| 6875.0000 |
+------------+
1 row in set (0.00 sec)
6. Select count(Distinct Brand_Name) from product;

mysql> Select count(Distinct Brand_Name) from product;


+----------------------------+
| count(Distinct Brand_Name) |
+----------------------------+
| 4 |
+----------------------------+
1 row in set (0.00 sec)

7. Select max(Price) from product;

mysql> Select max(Price) from product;


+------------+
| max(Price) |
+------------+
| 12500 |
+------------+
1 row in set (0.00 sec)

You might also like