SQL Program File
SQL Program File
FILE
Q)-to display iname, type ,size of those where margin is not inserted.
mysql> select iname,type,qty
-> from item
-> where margin is null;
+----------------+--------+------+
| iname | type | qty |
+----------------+--------+------+
| school leather | school | 1100 |
| tracker | sports | 280 |
+----------------+--------+------+
2 rows in set (0.00 sec)
Q)-to display item name and price whose price is less than 300.
mysql> select iname,type
-> from item
-> where cost<300;
+----------------+--------+
| iname | type |
+----------------+--------+
| school canvas | school |
| school canvas | school |
| school canvas | school |
| school canvas | school |
| school leather | school |
+----------------+--------+
5 rows in set (0.00 sec)
Q)-to display item info whose price in b/w 300 and 700.
mysql> select*
-> from item
-> where cost between 300 and 700;
+-------+----------------+--------+------+--------+--------+------+
| icode | iname | type | size | cost | margin | qty |
+-------+----------------+--------+------+--------+--------+------+
| 1013 | school leather | school | 8 | 320.23 | NULL | 1100 |
| 1101 | galaxy | office | 7 | 640.03 | 3.00 | 200 |
| 1201 | tracker | sports | 8 | 700.00 | NULL | 280 |
+-------+----------------+--------+------+--------+--------+------+
3 rows in set (0.00 sec)
Q)-to display name , price and quantity whose price is more than 500 and
type is office.
mysql> select iname,cost,qty
-> from item
-> where cost>500 and type='office';
+--------+--------+------+
| iname | cost | qty |
+--------+--------+------+
| galaxy | 640.03 | 200 |
| galaxy | 712.65 | 500 |
| galaxy | 720.65 | 400 |
+--------+--------+------+
3 rows in set (0.00 sec)
Q)-to display price and quantity whose item name start with s.
mysql> select cost,qty
-> from item
-> where iname like"s%";
+--------+------+
| cost | qty |
+--------+------+
| 132.50 | 1200 |
| 155.50 | 800 |
| 145.50 | 600 |
| 232.50 | 2200 |
| 232.50 | 1280 |
| 320.23 | 1100 |
+--------+------+
6 rows in set (0.00 sec)
Q)-to display item info in descending order of name and ascending order of price.
mysql> select*
-> from item
-> order by iname desc,cost;
+-------+----------------+--------+------+--------+--------+------+
| icode | iname | type | size | cost | margin | qty |
+-------+----------------+--------+------+--------+--------+------+
| 1201 | tracker | sports | 8 | 700.00 | NULL | 280 |
| 1202 | tracker | sports | 7 | 745.00 | 3.50 | NULL |
| 1203 | tracker | sports | 6 | 800.00 | 3.50 | 600 |
| 1204 | tracker | sports | 9 | 850.00 | 3.50 | NULL |
| 1012 | school leather | school | 6 | 232.50 | 2.00 | 1280 |
| 1013 | school leather | school | 8 | 320.23 | NULL | 1100 |
| 1001 | school canvas | school | 6 | 132.50 | 2.00 | 1200 |
| 1003 | school canvas | school | 8 | 145.50 | 2.00 | 600 |
| 1002 | school canvas | school | 7 | 155.50 | 2.00 | 800 |
| 1011 | school canvas | school | 6 | 232.50 | 2.00 | 2200 |
| 1101 | galaxy | office | 7 | 640.03 | 3.00 | 200 |
| 1102 | galaxy | office | 8 | 712.65 | 3.00 | 500 |
| 1103 | galaxy | office | 8 | 720.65 | 3.00 | 400 |
+-------+----------------+--------+------+--------+--------+------+
13 rows in set (0.00 sec)
-> phone
varchar(22));
affected (0.24
sec)
mysql> insert
into student
student
-> values(1325,"md.yusuf",10,'a',2,'12/21
student
->
values(1328,'sumedha',10,'b',23,'59,moti
student
-> values(1364,'subya
akyhar',11,'b',13,'12,janakpuri',null);
values(1434,'varuna',12,'b',21,'
-> values(2324,'satinder
singh',12,'c',1,'1/2-gulmohar park',143654);
-> values(2328,'peter
jones',10,'a',18,'21/32b,vishalenclave',24356154);
into student
Sports table:-
references student(admno));
->
values(1324,'cricket','n
sports
->
values(1364,'volleball','
m.p.singh','a'); Query
into sports
->
values(1271,'volleball','
m.p.singh','b'); Query
into sports
->
values(1434,'basketball','
i.malhotra','b'); Query
sports
->
values(1461,'cricket','n
sports
->
values(2328,'basketball','
i.malhotra','a'); Query
sports
-> values(2371,'basketball','i.malhotra','a');
->
values(2371,'basketball','
i.malhotra','a'); Query
sports
->
values(1271,'basketball','
i.malhotra','a'); Query
sports
->
values(1434,'cricket','n
sports
->
values(2328,'cricket','n
sports
-> values(1364,'basketball','i.malhotra','b');