Program 4

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

mysql> create table Shopee

-> (Scode int(10) primary key,PName varchar(20),SupName varchar(20),Qty


int(10),City varchar(20),Price float(10));
Query OK, 0 rows affected, 2 warnings (0.01 sec)

mysql> desc Shopee;


+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| Scode | int | NO | PRI | NULL | |
| PName | varchar(20) | YES | | NULL | |
| SupName | varchar(20) | YES | | NULL | |
| Qty | int | YES | | NULL | |
| City | varchar(20) | YES | | NULL | |
| Price | float | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> insert into Shopee


-> values(102,'Biscuit','Hide and Seek',100,'Delhi',10);
Query OK, 1 row affected (0.01 sec)

mysql> insert into Shopee


-> values(103,'Jam','Kissan',110,'Kolkata',25);
Query OK, 1 row affected (0.01 sec)

mysql> insert into Shopee


-> values(101,'Coffee','Nestle',200,'Kolkata',55);
Query OK, 1 row affected (0.00 sec)

mysql> insert into Shopee


-> values(106,'Sauce','Maggi',56,'Mumbai',55);
Query OK, 1 row affected (0.01 sec)

mysql> insert into Shopee


-> values(107,'Cake','Britania',72,'Delhi',10);
Query OK, 1 row affected (0.01 sec)

mysql> insert into Shopee


-> values(104,'Maggi','Nestle',150,'Mumbai',10);
Query OK, 1 row affected (0.01 sec)

mysql> insert into Shopee


-> values(105,'Chocolate','Cadbury',170,'Delhi',25);
Query OK, 1 row affected (0.05 sec)

mysql> select * from Shopee;


+-------+-----------+---------------+------+---------+-------+
| Scode | PName | SupName | Qty | City | Price |
+-------+-----------+---------------+------+---------+-------+
| 101 | Coffee | Nestle | 200 | Kolkata | 55 |
| 102 | Biscuit | Hide and Seek | 100 | Delhi | 10 |
| 103 | Jam | Kissan | 110 | Kolkata | 25 |
| 104 | Maggi | Nestle | 150 | Mumbai | 10 |
| 105 | Chocolate | Cadbury | 170 | Delhi | 25 |
| 106 | Sauce | Maggi | 56 | Mumbai | 55 |
| 107 | Cake | Britania | 72 | Delhi | 10 |
+-------+-----------+---------------+------+---------+-------+
7 rows in set (0.00 sec)
Questions:-
1. To display names of the product whose name starts with 'C' in ascending order of
Price.

mysql> select PName from shopee where PName like 'C%' order by Price asc;
+-----------+
| PName |
+-----------+
| Cake |
| Chocolate |
| Coffee |
+-----------+
3 rows in set (0.00 sec)

2. To Display Scode,PName and city of the products whose Qty is less than 100.

mysql> select Scode,PName,City,Qty from shopee where Qty<100;


+-------+-------+--------+------+
| Scode | PName | City | Qty |
+-------+-------+--------+------+
| 106 | Sauce | Mumbai | 56 |
| 107 | Cake | Delhi | 72 |
+-------+-------+--------+------+
2 rows in set (0.00 sec)

3. To Count Distinct SupName in the table.

mysql> select count(Distinct SupName) from shopee;


+-------------------------+
| count(Distinct SupName) |
+-------------------------+
| 6 |
+-------------------------+
1 row in set (0.00 sec)

4. To Insert a new row in the table shopee [110,'Pizza','Papa


Jones',120,'Kolkata',50.00]

mysql> insert into shopee


-> values(110,'Pizza','Papa Jones',120,'Kolkata',50.00);
Query OK, 1 row affected (0.00 sec)

mysql> select * from shopee;


+-------+-----------+---------------+------+---------+-------+
| Scode | PName | SupName | Qty | City | Price |
+-------+-----------+---------------+------+---------+-------+
| 101 | Coffee | Nestle | 200 | Kolkata | 55 |
| 102 | Biscuit | Hide and Seek | 100 | Delhi | 10 |
| 103 | Jam | Kissan | 110 | Kolkata | 25 |
| 104 | Maggi | Nestle | 150 | Mumbai | 10 |
| 105 | Chocolate | Cadbury | 170 | Delhi | 25 |
| 106 | Sauce | Maggi | 56 | Mumbai | 55 |
| 107 | Cake | Britania | 72 | Delhi | 10 |
| 110 | Pizza | Papa Jones | 120 | Kolkata | 50 |
+-------+-----------+---------------+------+---------+-------+
8 rows in set (0.00 sec)

5. Select PName from shopee where PName IN ('Jam','Coffee').

mysql> select PName from shopee where PName IN ('Jam','Coffee');


+--------+
| PName |
+--------+
| Coffee |
| Jam |
+--------+
2 rows in set (0.00 sec)

6. Select count(Distinct City) from shopee.

mysql> select count(Distinct City) from shopee;


+----------------------+
| count(Distinct City) |
+----------------------+
| 3 |
+----------------------+
1 row in set (0.00 sec)

7. Select max(Qty) from shopee where City='Mumbai'.

mysql> select max(Qty) from shopee where City='Mumbai';


+----------+
| max(Qty) |
+----------+
| 150 |
+----------+
1 row in set (0.00 sec)

You might also like