Sei sulla pagina 1di 26

Q4.

Pg461
mysql> create database bhamra;
Query OK, 1 row affected (0.00 sec)
mysql> use bhamra;
Database changed
mysql> create table CLUB(COACH_ID char(2),COACHNAME char(10),AGE int(2),SPORTS c
har(10),DATOFAPP char(10),PAY int(4),SEX char(1));
Query OK, 0 rows affected (0.06 sec)
mysql> insert into CLUB values("1.","KUKREJA",35,"KARATE","27/03/1996",1000,"M");
Query OK, 1 row affected (0.03 sec)
mysql> insert into CLUB values("2.","RAVINA",34,"KARATE","20/01/1998",1200,"F");
Query OK, 1 row affected (0.03 sec)
mysql> insert into CLUB values("3.","KARAN",34,"SQUASH","19/02/1998",2000,"M");
Query OK, 1 row affected (0.02 sec)
mysql> insert into CLUB values("4.","TARUN",33,"BASKETBALL","01/01/1998",1500,"M");
Query OK, 1 row affected (0.03 sec)
mysql> insert into CLUB values("5.","ZUBIN",36,"SWIMMING","12/01/1998",750,"M");
Query OK, 1 row affected (0.01 sec)
mysql> insert into CLUB values("6.","KETAKI",36,"SWIMMING","24/02/1998",800,"F");
Query OK, 1 row affected (0.02 sec)
mysql> insert into CLUB values("7.","ANKITA",39,"SQUASH","20/02/1998",2200,"F");
Query OK, 1 row affected (0.03 sec)

mysql> insert into CLUB values("8.","ZAREEN",37,"KARATE","22/02/1998",1100,"F");


Query OK, 1 row affected (0.03 sec)
mysql> insert into CLUB values("9.","KUSH",41,"SWIMMING","13/01/1998",900,"M");
Query OK, 1 row affected (0.02 sec)
mysql> insert into CLUB values("10","SHAILYA",37,"BASKETBALL","19/02/1998",1700,"M");
Query OK, 1 row affected (0.05 sec)

mysql> SELECT * FROM CLUB;


+----------+-----------+------+------------+------------+------+------+
| COACH_ID | COACHNAME | AGE | SPORTS | DATOFAPP | PAY | SEX |
+----------+-----------+------+------------+------------+------+------+
| 1.
| KUKREJA | 35 | KARATE | 27/03/1996 | 1000 | M |
| 2.
| RAVINA | 34 | KARATE | 20/01/1998 | 1200 | F |
| 3.
| KARAN | 34 | SQUASH | 19/02/1998 | 2000 | M |
| 4.
| TARUN | 33 | BASKETBALL | 01/01/1998 | 1500 | M |
| 5.
| ZUBIN | 36 | SWIMMING | 12/01/1998 | 750 | M |
| 6.
| KETAKI | 36 | SWIMMING | 24/02/1998 | 800 | F |
| 7.
| ANKITA | 39 | SQUASH | 20/02/1998 | 2200 | F |

| 8.
| ZAREEN | 37 | KARATE | 22/02/1998 | 1100 | F |
| 9.
| KUSH
| 41 | SWIMMING | 13/01/1998 | 900 | M |
| 10
| SHAILYA | 37 | BASKETBALL | 19/02/1998 | 1700 | M
+----------+-----------+------+------------+------------+------+------+
10 rows in set (0.00 sec)

mysql> SELECT * FROM CLUB WHERE SPORTS="SWIMMING";


+----------+-----------+------+----------+------------+------+------+
| COACH_ID | COACHNAME | AGE | SPORTS | DATOFAPP | PAY | SEX |
+----------+-----------+------+----------+------------+------+------+
| 5.
| ZUBIN | 36 | SWIMMING | 12/01/1998 | 750 | M |
| 6.
| KETAKI | 36 | SWIMMING | 24/02/1998 | 800 | F |
| 9.
| KUSH
| 41 | SWIMMING | 13/01/1998 | 900 | M |
+----------+-----------+------+----------+------------+------+------+
3 rows in set (0.00 sec)
mysql> SELECT COACHNAME,DATOFAPP FROM CLUB ORDER BY(DATOFAPP);
+-----------+------------+
| COACHNAME | DATOFAPP |
+-----------+------------+
| TARUN | 01/01/1998 |
| ZUBIN | 12/01/1998 |
| KUSH
| 13/01/1998 |
| SHAILYA | 19/02/1998 |
| KARAN | 19/02/1998 |
| RAVINA | 20/01/1998 |
| ANKITA | 20/02/1998 |
| ZAREEN | 22/02/1998 |
| KETAKI | 24/02/1998 |
| KUKREJA | 27/03/1996 |
+-----------+------------+
10 rows in set (0.00 sec)
mysql> SELECT COACHNAME,PAY,AGE,PAY*0.15 AS BONUS FROM CLUB;
+-----------+------+------+--------+
| COACHNAME | PAY | AGE | BONUS |
+-----------+------+------+--------+
| KUKREJA | 1000 | 35 | 150.00 |
| RAVINA | 1200 | 34 | 180.00 |
| KARAN | 2000 | 34 | 300.00 |
| TARUN | 1500 | 33 | 225.00 |
| ZUBIN | 750 | 36 | 112.50 |
| KETAKI | 800 | 36 | 120.00 |
| ANKITA | 2200 | 39 | 330.00 |
| ZAREEN | 1100 | 37 | 165.00 |
| KUSH
| 900 | 41 | 135.00 |
| SHAILYA | 1700 | 37 | 255.00 |
+-----------+------+------+--------+
10 rows in set (0.00 sec)
mysql> SELECT LCASE(SPORTS) FROM CLUB;
+---------------+
| LCASE(SPORTS) |
+---------------+
| karate
|
| karate
|

| squash
|
| basketball |
| swimming
|
| swimming
|
| squash
|
| karate
|
| swimming
|
| basketball |
+---------------+
10 rows in set (0.01 sec)
mysql> SELECT MOD(AGE,5) FROM CLUB WHERE SEX="F";
+------------+
| MOD(AGE,5) |
+------------+
|
4|
|
1|
|
4|
|
2|
+------------+
4 rows in set (0.00 sec)
mysql> SELECT POWER(3,2) FROM CLUB WHERE SPORTS="KARATE";
+------------+
| POWER(3,2) |
+------------+
|
9|
|
9|
|
9|
+------------+
3 rows in set (0.03 sec)
mysql> SELECT SUBSTR(COACHNAME,1,2) FROM CLUB WHERE DATOFAPP>"1998-01-31";
+-----------------------+
| SUBSTR(COACHNAME,1,2) |
+-----------------------+
| KU
|
| RA
|
| KE
|
| AN
|
| ZA
|
+-----------------------+
5 rows in set (0.00 sec)

Q5.Pg461
mysql> create table student1(no int(2),name char(10),stipend decimal(6,2),stream
char(10),avgmark decimal(3,1),grade char(2),class char(3));
Query OK, 0 rows affected (0.05 sec)
mysql> insert into student1 values(1,"karan",400.00,"medical",78.5,"b","12b");
Query OK, 1 row affected (0.03 sec)

mysql> insert into student1 values(2,"divakar",450.00,"commerce",89.2,"a","11c");


Query OK, 1 row affected (0.03 sec)
mysql> insert into student1 values(3,"divya",300.00,"commerce",68.6,"c","12c");
Query OK, 1 row affected (0.00 sec)
mysql> insert into student1 values(4,"arun",350.00,"humanities",73.1,"b","12c");
Query OK, 1 row affected (0.03 sec)
mysql> insert into student1 values(5,"sabina",500.00,"nonmedical",90.6,"a","11a");
Query OK, 1 row affected (0.03 sec)
mysql> insert into student1 values(6,"john",400.00,"medical",75.4,"b","12b");
Query OK, 1 row affected (0.02 sec)
mysql> insert into student1 values(7,"robert",250.00,"humanities",64.4,"c","11a");
Query OK, 1 row affected (0.03 sec)
mysql> insert into student1 values(8,"rubina",450.00,"nonmedical",88.5,"a","12a");
Query OK, 1 row affected (0.01 sec)
mysql> insert into student1 values(9,"vikas",500.00,"nonmedical",92.0,"a","12a");
Query OK, 1 row affected (0.03 sec)
mysql> insert into student1 values(10,"mohan",300.00,"commerce",67.5,"c","12c");
Query OK, 1 row affected (0.00 sec)
mysql> select * from student1;
+------+---------+---------+------------+---------+-------+-------+
| no | name | stipend | stream | avgmark | grade | class |
+------+---------+---------+------------+---------+-------+-------+
| 1 | karan | 400.00 | medical | 78.5 | b | 12b |
| 2 | divakar | 450.00 | commerce | 89.2 | a | 11c |
| 3 | divya | 300.00 | commerce | 68.6 | c | 12c |
| 4 | arun | 350.00 | humanities | 73.1 | b | 12c |
| 5 | sabina | 500.00 | nonmedical | 90.6 | a | 11a |
| 6 | john | 400.00 | medical | 75.4 | b | 12b |
| 7 | robert | 250.00 | humanities | 64.4 | c | 11a |
| 8 | rubina | 450.00 | nonmedical | 88.5 | a | 12a |
| 9 | vikas | 500.00 | nonmedical | 92.0 | a | 12a |
| 10 | mohan | 300.00 | commerce | 67.5 | c | 12c |
+------+---------+---------+------------+---------+-------+-------+
10 rows in set (0.00 sec)
mysql> select * from student1 where stream="nonmedical";
+------+--------+---------+------------+---------+-------+-------+
| no | name | stipend | stream | avgmark | grade | class |
+------+--------+---------+------------+---------+-------+-------+
| 5 | sabina | 500.00 | nonmedical | 90.6 | a | 11a |
| 8 | rubina | 450.00 | nonmedical | 88.5 | a | 12a |
| 9 | vikas | 500.00 | nonmedical | 92.0 | a | 12a |
+------+--------+---------+------------+---------+-------+-------+
3 rows in set (0.02 sec)

mysql> select name from student1 where class like "12_" order by stipend;
+--------+
| name |
+--------+
| divya |
| mohan |
| arun |
| karan |
| john |
| rubina |
| vikas |
+--------+
7 rows in set (0.02 sec)
mysql> select * from student1 order by avgmark desc;
+------+---------+---------+------------+---------+-------+-------+
| no | name | stipend | stream | avgmark | grade | class |
+------+---------+---------+------------+---------+-------+-------+
| 9 | vikas | 500.00 | nonmedical | 92.0 | a | 12a |
| 5 | sabina | 500.00 | nonmedical | 90.6 | a | 11a |
| 2 | divakar | 450.00 | commerce | 89.2 | a | 11c |
| 8 | rubina | 450.00 | nonmedical | 88.5 | a | 12a |
| 1 | karan | 400.00 | medical | 78.5 | b | 12b |
| 6 | john | 400.00 | medical | 75.4 | b | 12b |
| 4 | arun | 350.00 | humanities | 73.1 | b | 12c |
| 3 | divya | 300.00 | commerce | 68.6 | c | 12c |
| 10 | mohan | 300.00 | commerce | 67.5 | c | 12c |
| 7 | robert | 250.00 | humanities | 64.4 | c | 11a |
+------+---------+---------+------------+---------+-------+-------+
10 rows in set (0.00 sec)
mysql> select name,stipend,stream,stipend*12 as amount from student1;
+---------+---------+------------+---------+
| name | stipend | stream | amount |
+---------+---------+------------+---------+
| karan | 400.00 | medical | 4800.00 |
| divakar | 450.00 | commerce | 5400.00 |
| divya | 300.00 | commerce | 3600.00 |
| arun | 350.00 | humanities | 4200.00 |
| sabina | 500.00 | nonmedical | 6000.00 |
| john | 400.00 | medical | 4800.00 |
| robert | 250.00 | humanities | 3000.00 |
| rubina | 450.00 | nonmedical | 5400.00 |
| vikas | 500.00 | nonmedical | 6000.00 |
| mohan | 300.00 | commerce | 3600.00 |
+---------+---------+------------+---------+
10 rows in set (0.00 sec)
mysql> select round(avgmark) from student1 where grade="b";
+----------------+
| round(avgmark) |
+----------------+
|
79 |
|
73 |
|
75 |

+----------------+
3 rows in set (0.02 sec)
mysql> select concat(name,stream) from student1 where class="12a";
+---------------------+
| concat(name,stream) |
+---------------------+
| rubinanonmedical |
| vikasnonmedical |
+---------------------+
2 rows in set (0.01 sec)
mysql> select right(stream,2) from student1;
+-----------------+
| right(stream,2) |
+-----------------+
| al
|
| ce
|
| ce
|
| es
|
| al
|
| al
|
| es
|
| al
|
| al
|
| ce
|
+-----------------+
10 rows in set (0.00 sec)

EXAMPLE 14.3Page473
mysql> create table t3(code int(1),grade char(1),value int(3));
Query OK, 0 rows affected (0.05 sec)
mysql> insert into t3 values(1,"g",510);
Query OK, 1 row affected (0.03 sec)
mysql> insert into t3 values(2,"k",600);
Query OK, 1 row affected (0.01 sec)
mysql> insert into t3 values(3,"b",200);
Query OK, 1 row affected (0.03 sec)
mysql> insert into t3 values(4,"a",100);
Query OK, 1 row affected (0.02 sec)
mysql> select * from t3;
+-------+---------+--------+
| code | grade | value |
+-------+---------+--------+
| 1 |g
| 510 |
| 2 |k
| 600 |
| 3 |b
| 200 |

| 4 |a
| 100 |
+-------+---------+--------+
4 rows in set (0.00 sec)
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)
mysql> update t3 set value=550 where code=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from t3;
+------+-------+-------+
| code | grade | value |
+------+-------+-------+
| 1 | g | 550 |
| 2 | k | 600 |
| 3 | b | 200 |
| 4 | a | 100 |
+------+-------+-------+
4 rows in set (0.00 sec)
mysql> insert into t3 values(70,"f",90);
Query OK, 1 row affected (0.00 sec)
mysql> select * from t3;
+------+-------+-------+
| code | grade | value |
+------+-------+-------+
| 1 | g | 550 |
| 2 | k | 600 |
| 3 | b | 200 |
| 4 | a | 100 |
| 70 | f | 90 |
+------+-------+-------+
5 rows in set (0.00 sec)
mysql> savepoint s1;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into t3 values(80,"l",90);
Query OK, 1 row affected (0.00 sec)
mysql> select * from t3;
+------+-------+-------+
| code | grade | value |
+------+-------+-------+
| 1 | g | 550 |
| 2 | k | 600 |
| 3 | b | 200 |
| 4 | a | 100 |
| 70 | f | 90 |
| 80 | l | 90 |
+------+-------+-------+
6 rows in set (0.00 sec)

mysql> savepoint s2;


Query OK, 0 rows affected (0.00 sec)
mysql> delete from t3 where code=70;
Query OK, 1 row affected (0.00 sec)
mysql> select * from t3;
+------+-------+-------+
| code | grade | value |
+------+-------+-------+
| 1 | g | 550 |
| 2 | k | 600 |
| 3 | b | 200 |
| 4 | a | 100 |
| 80 | l | 90 |
+------+-------+-------+
5 rows in set (0.00 sec)
mysql> rollback work to savepoint s2;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from t3;
+------+-------+-------+
| code | grade | value |
+------+-------+-------+
| 1 | g | 550 |
| 2 | k | 600 |
| 3 | b | 200 |
| 4 | a | 100 |
| 70 | f | 90 |
| 80 | l | 90 |
+------+-------+-------+
6 rows in set (0.00 sec)
mysql> update t3 set value=990 where code=2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from t3;
+------+-------+-------+
| code | grade | value |
+------+-------+-------+
| 1 | g | 550 |
| 2 | k | 990 |
| 3 | b | 200 |
| 4 | a | 100 |
| 70 | f | 90 |
| 80 | l | 90 |
+------+-------+-------+
6 rows in set (0.00 sec)
mysql> rollback work to savepoint s1;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from t3;
+------+-------+-------+

| code | grade | value |


+------+-------+-------+
| 1 | g | 550 |
| 2 | k | 600 |
| 3 | b | 200 |
| 4 | a | 100 |
| 70 | f | 90 |
+------+-------+-------+
5 rows in set (0.00 sec)
mysql> update t3 set value=510 where code=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from t3;
+------+-------+-------+
| code | grade | value |
+------+-------+-------+
| 1 | g | 510 |
| 2 | k | 600 |
| 3 | b | 200 |
| 4 | a | 100 |
| 70 | f | 90 |
+------+-------+-------+
5 rows in set (0.00 sec)
mysql> commit work;
Query OK, 0 rows affected (0.02 sec)
mysql> select * from t3;
+------+-------+-------+
| code | grade | value |
+------+-------+-------+
| 1 | g | 510 |
| 2 | k | 600 |
| 3 | b | 200 |
| 4 | a | 100 |
| 70 | f | 90 |
+------+-------+-------+
5 rows in set (0.02 sec)

Q bPg330 of cbse book


mysql> create table item(icode int(3),iname char(15),iprice decimal(7,2));
Query OK, 0 rows affected (0.05 sec)
mysql> insert into item values(101,"chair",1500.00);
Query OK, 1 row affected (0.03 sec)
mysql> insert into item values(102,"dining table",24000.00);
Query OK, 1 row affected (0.01 sec)
mysql> select * from item;
+-------+--------------+----------+
| icode | iname
| iprice |
+-------+--------------+----------+
| 101 | chair
| 1500.00 |
| 102 | dining table | 24000.00 |
+-------+--------------+----------+
2 rows in set (0.00 sec)
mysql> set autocommit=0;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into item values(103,"coffee table",340);
Query OK, 1 row affected (0.00 sec)
mysql> select * from item;
+-------+--------------+----------+
| icode | iname
| iprice |
+-------+--------------+----------+
| 101 | chair
| 1500.00 |
| 102 | dining table | 24000.00 |
| 103 | coffee table | 340.00 |
+-------+--------------+----------+
3 rows in set (0.00 sec)
mysql> start transaction;
Query OK, 0 rows affected (0.03 sec)
mysql> update item set iprice=iprice+200;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> savepoint s1;
Query OK, 0 rows affected (0.00 sec)
mysql> update item set iprice=iprice+400;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> select * from item;
+-------+--------------+----------+
| icode | iname
| iprice |
+-------+--------------+----------+
| 101 | chair
| 2100.00 |
| 102 | dining table | 24600.00 |

| 103 | coffee table | 940.00 |


+-------+--------------+----------+
3 rows in set (0.00 sec)
mysql> rollback to s1;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from item;
+-------+--------------+----------+
| icode | iname
| iprice |
+-------+--------------+----------+
| 101 | chair
| 1700.00 |
| 102 | dining table | 24200.00 |
| 103 | coffee table | 540.00 |
+-------+--------------+----------+
3 rows in set (0.00 sec)

Q2.a Equi Join


The join in which columns are compared for equality, is called equi-join. Italways happens that
whenever we have to get data from more than one tables, there is some common column based on which
the meaningful date is extracted from the tables. We specify table names in the FROM clause of SELECT
command. We also give condition specifying the matching of common column. Corresponding to this
statement, internally a cartesian product of tables is made and then based on specified condition
meaningful data is extracted.
example
mysql> create table cart(ord int(1),scode char(4),pcode char(4));
Query OK, 0 rows affected (0.05 sec)
mysql> insert into cart values(1,"s002","poo1");
Query OK, 1 row affected (0.03 sec)
mysql> insert into cart values(2,"s002","poo2");
Query OK, 1 row affected (0.03 sec)
mysql> select * from cart;
+------+-------+-------+
| ord | scode | pcode |
+------+-------+-------+
| 1 | s002 | poo1 |
| 2 | s002 | poo2 |
+------+-------+-------+
2 rows in set (0.00 sec)
mysql> create table cart2(code char(4),name char(10));
Query OK, 0 rows affected (0.05 sec)
mysql> insert into cart2 values("poo1","toothpaste");
Query OK, 1 row affected (0.02 sec)
mysql> insert into cart2 values("poo2","shampoo");
Query OK, 1 row affected (0.03 sec)
mysql> insert into cart2 values("poo3","condition");
Query OK, 1 row affected (0.02 sec)

mysql> select * from cart2;


+------+------------+
| code | name
|
+------+------------+
| poo1 | toothpaste |
| poo2 | shampoo |
| poo3 | condition |
+------+------------+
3 rows in set (0.00 sec)
mysql> select * from cart,cart2 where pcode=code;
+------+-------+-------+------+------------+
| ord | scode | pcode | code | name
|
+------+-------+-------+------+------------+
| 1 | s002 | poo1 | poo1 | toothpaste |
| 2 | s002 | poo2 | poo2 | shampoo |
+------+-------+-------+------+------------+
2 rows in set (0.02 sec)

(b)Cartesian Product
Cartesian product (also known as cross join) of two tables is a table obtained by pairing up each
row of one table with each row of other table. The number of columns in the cartesian product is
the sum of number of columns in both the tables. In SQL, cartesian product of two rows is
obtained by giving the names of both tables in FROM clause.
example:
mysql> create table cart(ord int(1),scode char(4),pcode char(4));
Query OK, 0 rows affected (0.05 sec)
mysql> insert into cart values(1,"s002","poo1");
Query OK, 1 row affected (0.03 sec)
mysql> insert into cart values(2,"s002","poo2");
Query OK, 1 row affected (0.03 sec)
mysql> select * from cart;
+------+-------+-------+
| ord | scode | pcode |
+------+-------+-------+
| 1 | s002 | poo1 |
| 2 | s002 | poo2 |
+------+-------+-------+
2 rows in set (0.00 sec)
mysql> create table cart2(code char(4),name char(10));
Query OK, 0 rows affected (0.05 sec)
mysql> insert into cart2 values("poo1","toothpaste");
Query OK, 1 row affected (0.02 sec)
mysql> insert into cart2 values("poo2","shampoo");
Query OK, 1 row affected (0.03 sec)

mysql> insert into cart2 values("poo3","condition");


Query OK, 1 row affected (0.02 sec)
mysql> select * from cart2;
+------+------------+
| code | name
|
+------+------------+
| poo1 | toothpaste |
| poo2 | shampoo |
| poo3 | condition |
+------+------------+
3 rows in set (0.00 sec)
mysql> select * from cart,cart2;
+------+-------+-------+------+------------+
| ord | scode | pcode | code | name
|
+------+-------+-------+------+------------+
| 1 | s002 | poo1 | poo1 | toothpaste |
| 2 | s002 | poo2 | poo1 | toothpaste |
| 1 | s002 | poo1 | poo2 | shampoo |
| 2 | s002 | poo2 | poo2 | shampoo |
| 1 | s002 | poo1 | poo3 | condition |
| 2 | s002 | poo2 | poo3 | condition |
+------+-------+-------+------+------------+
6 rows in set (0.00 sec)

Q15-18 Pg510
mysql> create table customers(name char(10),address char(10),state char(2),zip int(5),phone
char(8),remarks char(8));
Query OK, 0 rows affected (0.08 sec)
mysql> insert into customers values("true wheel","550 husker","ne",58702,"555-4545","none");
Query OK, 1 row affected (0.03 sec)
mysql> insert into customers values("bike spec","cpt shrive","la",45678,"555-1234","none");
Query OK, 1 row affected (0.01 sec)
mysql> insert into customers values("le shoppe","hometown","ks",54678,"555-1278","none");
Query OK, 1 row affected (0.01 sec)
mysql> insert into customers values("aaa bike","10 oldtown","ne",56784,"555-3421","john-mgr");
Query OK, 1 row affected (0.02 sec)
mysql> insert into customers values("jacks bike","24 eglin","fl",34567,"555-2314","none");
Query OK, 1 row affected (0.02 sec)
mysql> select* from customers;
+------------+------------+-------+-------+----------+----------+
| name
| address | state | zip | phone | remarks |
+------------+------------+-------+-------+----------+----------+
| true wheel | 550 husker | ne | 58702 | 555-4545 | none |
| bike spec | cpt shrive | la | 45678 | 555-1234 | none |
| le shoppe | hometown | ks | 54678 | 555-1278 | none |
| aaa bike | 10 oldtown | ne | 56784 | 555-3421 | john-mgr |

| jacks bike | 24 eglin | fl | 34567 | 555-2314 | none


+------------+------------+-------+-------+----------+----------+
5 rows in set (0.00 sec)

mysql> create table parts(partnum int(2),description char(15),price decimal(6,2));


Query OK, 0 rows affected (0.06 sec)
mysql> insert into parts values(54,"pedals",54.25);
Query OK, 1 row affected (0.03 sec)
mysql> insert into parts values(42,"seats",24.50);
Query OK, 1 row affected (0.03 sec)
mysql> insert into parts values(46,"tires",15.25);
Query OK, 1 row affected (0.03 sec)
mysql> insert into parts values(23,"mountain bike",350.45);
Query OK, 1 row affected (0.03 sec)
mysql> insert into parts values(76,"road bike",530.00);
Query OK, 1 row affected (0.02 sec)
mysql> insert into parts values(10,"tandem",1200.00);
Query OK, 1 row affected (0.01 sec)
mysql> select * from parts;
+---------+---------------+---------+
| partnum | description | price |
+---------+---------------+---------+
|
54 | pedals
| 54.25 |
|
42 | seats
| 24.50 |
|
46 | tires
| 15.25 |
|
23 | mountain bike | 350.45 |
|
76 | road bike | 530.00 |
|
10 | tandem
| 1200.00 |
+---------+---------------+---------+
6 rows in set (0.00 sec)

mysql> create table orders(orderedon char(12),name char(10),partnum int(2),quant


ity int(2),remarks char(4));
Query OK, 0 rows affected (0.05 sec)
mysql> insert into orders value("15-may-1996","true wheel",23,6,"paid");
Query OK, 1 row affected (0.03 sec)
mysql> insert into orders value("19-may-1996","true wheel",76,3,"paid");
Query OK, 1 row affected (0.03 sec)
mysql> insert into orders value("2-sep-1996","true wheel",10,1,"paid");
Query OK, 1 row affected (0.03 sec)
mysql> insert into orders value("30-june-1996","true wheel",42,8,"paid");
Query OK, 1 row affected (0.01 sec)
mysql> insert into orders value("30-june-1996","bike spec",54,10,"paid");

Query OK, 1 row affected (0.03 sec)


mysql> insert into orders value("30-may-1996","bike spec",10,2,"paid");
Query OK, 1 row affected (0.02 sec)
mysql> insert into orders value("30-may-1996","bike spec",23,8,"paid");
Query OK, 1 row affected (0.02 sec)
mysql> insert into orders value("17-jan-1996","bike spec",76,11,"paid");
Query OK, 1 row affected (0.05 sec)
mysql> insert into orders value("17-jan-1996","le shoppe",76,5,"paid");
Query OK, 1 row affected (0.02 sec)
mysql> insert into orders value("1-june-1996","le shoppe",10,3,"paid");
Query OK, 1 row affected (0.02 sec)
mysql> insert into orders value("1-june-1996","aaa bike",10,1,"paid");
Query OK, 1 row affected (0.03 sec)
mysql> insert into orders value("1-jul-1996","aaa bike",76,4,"paid");
Query OK, 1 row affected (0.02 sec)
mysql> insert into orders value("1-jul-1996","aaa bike",46,14,"paid");
Query OK, 1 row affected (0.02 sec)
mysql> insert into orders value("11-jul-1996","aaa bike",76,14,"paid");
Query OK, 1 row affected (0.01 sec)
mysql> select * from orders;
+--------------+------------+---------+----------+---------+
| orderedon | name
| partnum | quantity | remarks |
+--------------+------------+---------+----------+---------+
| 15-may-1996 | true wheel |
23 |
6 | paid |
| 19-may-1996 | true wheel |
76 |
3 | paid |
| 2-sep-1996 | true wheel |
10 |
1 | paid |
| 30-june-1996 | true wheel |
42 |
8 | paid |
| 30-june-1996 | bike spec |
54 |
10 | paid |
| 30-may-1996 | bike spec |
10 |
2 | paid |
| 30-may-1996 | bike spec |
23 |
8 | paid |
| 17-jan-1996 | bike spec |
76 |
11 | paid |
| 17-jan-1996 | le shoppe |
76 |
5 | paid |
| 1-june-1996 | le shoppe |
10 |
3 | paid |
| 1-june-1996 | aaa bike |
10 |
1 | paid |
| 1-jul-1996 | aaa bike |
76 |
4 | paid |
| 1-jul-1996 | aaa bike |
46 |
14 | paid |
| 11-jul-1996 | aaa bike |
76 |
14 | paid |
+--------------+------------+---------+----------+---------+
14 rows in set (0.00 sec)
mysql> select orderedon,name,ord.partnum,pr.partnum,description from orders ord,
parts pr;
+--------------+------------+---------+---------+---------------+
| orderedon | name
| partnum | partnum | description |
+--------------+------------+---------+---------+---------------+
| 15-may-1996 | true wheel |
23 |
54 | pedals
|

| 15-may-1996 | true wheel |


| 15-may-1996 | true wheel |
| 15-may-1996 | true wheel |
| 15-may-1996 | true wheel |
| 15-may-1996 | true wheel |
| 19-may-1996 | true wheel |
| 19-may-1996 | true wheel |
| 19-may-1996 | true wheel |
| 19-may-1996 | true wheel |
| 19-may-1996 | true wheel |
| 19-may-1996 | true wheel |
| 2-sep-1996 | true wheel |
| 2-sep-1996 | true wheel |
| 2-sep-1996 | true wheel |
| 2-sep-1996 | true wheel |
| 2-sep-1996 | true wheel |
| 2-sep-1996 | true wheel |
| 30-june-1996 | true wheel |
| 30-june-1996 | true wheel |
| 30-june-1996 | true wheel |
| 30-june-1996 | true wheel |
| 30-june-1996 | true wheel |
| 30-june-1996 | true wheel |
| 30-june-1996 | bike spec |
| 30-june-1996 | bike spec |
| 30-june-1996 | bike spec |
| 30-june-1996 | bike spec |
| 30-june-1996 | bike spec |
| 30-june-1996 | bike spec |
| 30-may-1996 | bike spec |
| 30-may-1996 | bike spec |
| 30-may-1996 | bike spec |
| 30-may-1996 | bike spec |
| 30-may-1996 | bike spec |
| 30-may-1996 | bike spec |
| 30-may-1996 | bike spec |
| 30-may-1996 | bike spec |
| 30-may-1996 | bike spec |
| 30-may-1996 | bike spec |
| 30-may-1996 | bike spec |
| 30-may-1996 | bike spec |
| 17-jan-1996 | bike spec |
| 17-jan-1996 | bike spec |
| 17-jan-1996 | bike spec |
| 17-jan-1996 | bike spec |
| 17-jan-1996 | bike spec |
| 17-jan-1996 | bike spec |
| 17-jan-1996 | le shoppe |
| 17-jan-1996 | le shoppe |
| 17-jan-1996 | le shoppe |
| 17-jan-1996 | le shoppe |
| 17-jan-1996 | le shoppe |
| 17-jan-1996 | le shoppe |
| 1-june-1996 | le shoppe |
| 1-june-1996 | le shoppe |
| 1-june-1996 | le shoppe |

23 |
23 |
23 |
23 |
23 |
76 |
76 |
76 |
76 |
76 |
76 |
10 |
10 |
10 |
10 |
10 |
10 |
42 |
42 |
42 |
42 |
42 |
42 |
54 |
54 |
54 |
54 |
54 |
54 |
10 |
10 |
10 |
10 |
10 |
10 |
23 |
23 |
23 |
23 |
23 |
23 |
76 |
76 |
76 |
76 |
76 |
76 |
76 |
76 |
76 |
76 |
76 |
76 |
10 |
10 |
10 |

42 | seats
|
46 | tires
|
23 | mountain bike |
76 | road bike |
10 | tandem
|
54 | pedals
|
42 | seats
|
46 | tires
|
23 | mountain bike |
76 | road bike |
10 | tandem
|
54 | pedals
|
42 | seats
|
46 | tires
|
23 | mountain bike |
76 | road bike |
10 | tandem
|
54 | pedals
|
42 | seats
|
46 | tires
|
23 | mountain bike |
76 | road bike |
10 | tandem
|
54 | pedals
|
42 | seats
|
46 | tires
|
23 | mountain bike |
76 | road bike |
10 | tandem
|
54 | pedals
|
42 | seats
|
46 | tires
|
23 | mountain bike |
76 | road bike |
10 | tandem
|
54 | pedals
|
42 | seats
|
46 | tires
|
23 | mountain bike |
76 | road bike |
10 | tandem
|
54 | pedals
|
42 | seats
|
46 | tires
|
23 | mountain bike |
76 | road bike |
10 | tandem
|
54 | pedals
|
42 | seats
|
46 | tires
|
23 | mountain bike |
76 | road bike |
10 | tandem
|
54 | pedals
|
42 | seats
|
46 | tires
|

| 1-june-1996 | le shoppe |
10 |
23 | mountain bike |
| 1-june-1996 | le shoppe |
10 |
76 | road bike |
| 1-june-1996 | le shoppe |
10 |
10 | tandem
|
| 1-june-1996 | aaa bike |
10 |
54 | pedals
|
| 1-june-1996 | aaa bike |
10 |
42 | seats
|
| 1-june-1996 | aaa bike |
10 |
46 | tires
|
| 1-june-1996 | aaa bike |
10 |
23 | mountain bike |
| 1-june-1996 | aaa bike |
10 |
76 | road bike |
| 1-june-1996 | aaa bike |
10 |
10 | tandem
|
| 1-jul-1996 | aaa bike |
76 |
54 | pedals
|
| 1-jul-1996 | aaa bike |
76 |
42 | seats
|
| 1-jul-1996 | aaa bike |
76 |
46 | tires
|
| 1-jul-1996 | aaa bike |
76 |
23 | mountain bike |
| 1-jul-1996 | aaa bike |
76 |
76 | road bike |
| 1-jul-1996 | aaa bike |
76 |
10 | tandem
|
| 1-jul-1996 | aaa bike |
46 |
54 | pedals
|
| 1-jul-1996 | aaa bike |
46 |
42 | seats
|
| 1-jul-1996 | aaa bike |
46 |
46 | tires
|
| 1-jul-1996 | aaa bike |
46 |
23 | mountain bike |
| 1-jul-1996 | aaa bike |
46 |
76 | road bike |
| 1-jul-1996 | aaa bike |
46 |
10 | tandem
|
| 11-jul-1996 | aaa bike |
76 |
54 | pedals
|
| 11-jul-1996 | aaa bike |
76 |
42 | seats
|
| 11-jul-1996 | aaa bike |
76 |
46 | tires
|
| 11-jul-1996 | aaa bike |
76 |
23 | mountain bike |
| 11-jul-1996 | aaa bike |
76 |
76 | road bike |
| 11-jul-1996 | aaa bike |
76 |
10 | tandem
|
+--------------+------------+---------+---------+---------------+
84 rows in set (0.00 sec)
mysql> select ord.orderedon,ord.name,ord.partnum,pr.partnum,pr.description from
orders ord,parts pr where ord.partnum=pr.partnum and pr.description="road bike";
+-------------+------------+---------+---------+-------------+
| orderedon | name
| partnum | partnum | description |
+-------------+------------+---------+---------+-------------+
| 19-may-1996 | true wheel |
76 |
76 | road bike |
| 17-jan-1996 | bike spec |
76 |
76 | road bike |
| 17-jan-1996 | le shoppe |
76 |
76 | road bike |
| 1-jul-1996 | aaa bike |
76 |
76 | road bike |
| 11-jul-1996 | aaa bike |
76 |
76 | road bike |
+-------------+------------+---------+---------+-------------+
5 rows in set (0.00 sec)
mysql> select sum(ord.quantity*pr.price)"total amount" from orders ord,parts pr
where ord.partnum=pr.partnum and pr.description="road bike";
+--------------+
| total amount |
+--------------+
| 19610.00 |
+--------------+
1 row in set (0.00 sec)
mysql> select * from orders where partnum=(select partnum from parts where descr
iption like"road%");
+-------------+------------+---------+----------+---------+

| orderedon | name
| partnum | quantity | remarks |
+-------------+------------+---------+----------+---------+
| 19-may-1996 | true wheel |
76 |
3 | paid |
| 17-jan-1996 | bike spec |
76 |
11 | paid |
| 17-jan-1996 | le shoppe |
76 |
5 | paid |
| 1-jul-1996 | aaa bike |
76 |
4 | paid |
| 11-jul-1996 | aaa bike |
76 |
14 | paid |
+-------------+------------+---------+----------+---------+
5 rows in set (0.00 sec)

(e)Q1 Pg308 of cbse book


mysql> create table students(admno int(4),name char(20),class int(2),sec char(1)
,rno int(2),address char(25),phone char(20));
Query OK, 0 rows affected (0.08 sec)
mysql> insert into students values(1271,"utkarsh madaan",12,"c",1,"c-32, punjabi
bagh","4356154");
Query OK, 1 row affected (0.05 sec)
mysql> insert into students values(1324,"naresh sharma",10,"a",1,"31, mohan naga
r","435654");
Query OK, 1 row affected (0.03 sec)
mysql> insert into students values(1325,"md. yusuf",10,"a",2,"12/21, chand nagar
","145654");
Query OK, 1 row affected (0.03 sec)
mysql> insert into students values(1328,"sumedha",10,"b",23,"59, moti nagar","41
35654");
Query OK, 1 row affected (0.05 sec)
mysql> insert into students values(1364,"subya akhtar",11,"b",13,"12, janak puri
",null);
Query OK, 1 row affected (0.02 sec)
mysql> insert into students values(1434,"varuna",12,"b",21,"69, rohini",null);
Query OK, 1 row affected (0.03 sec)
mysql> insert into students values(1461,"david dsouza",11,"b",1,"d-34, model tow
n","243554, 98787665");
Query OK, 1 row affected (0.03 sec)
mysql> insert into students values(2324,"satinder singh",12,"c",1,"1/2, gulmohar
park","143654");
Query OK, 1 row affected (0.02 sec)
mysql> insert into students values(2328,"peter jones",10,"a",10,"21/32b, vishal
enclave","24356154");
Query OK, 1 row affected (0.03 sec)
mysql> insert into students values(2371,"mohini mehta",11,"c",12,"37, raja garde
n","435654, 6765787");
Query OK, 1 row affected (0.01 sec)

mysql> select * from students;


+---------+-------------------------+---------+------+-------+-------------------------------+--------------------------+
| admno | name
| class | sec | rno | address
| phone
|
+----------+------------------------+---------+------+-------+------------------------------+----------------------------+
| 1271 | utkarsh madaan | 12 | c | 1 | c-32, punjabi bagh | 4356154
|
| 1324 | naresh sharma | 10 | a | 1 | 31, mohan nagar
| 435654
|
| 1325 | md. yusuf
| 10 | a | 2 | 12/21, chand nagar | 145654
|
| 1328 | sumedha
| 10 | b | 23 | 59, moti nagar
| 4135654
|
| 1364 | subya akhtar | 11 | b | 13 | 12, janak puri
| NULL
|
| 1434 | varuna
| 12 | b | 21 | 69, rohini
| NULL
|
| 1461 | david dsouza | 11 | b | 1 | d-34, model town
| 243554, 98787665 |
| 2324 | satinder singh | 12 | c | 1 | 1/2, gulmohar park
| 143654
|
| 2328 | peter jones
| 10 | a | 10 | 21/32b, vishal enclave | 24356154
|
| 2371 | mohini mehta | 11 | c | 12 | 37, raja garden
| 435654, 6765787 |
+----------+------------------------+--------+------+--------+--------------------------------+---------------------------+
10 rows in set (0.00 sec)
mysql> create table sports(admno int(4),game char(11),coachname char(15),grade c
har(1));
Query OK, 0 rows affected (0.05 sec)
mysql> insert into sports values(1324,"cricket","narendra","a");
Query OK, 1 row affected (0.03 sec)
mysql> insert into sports values(1364,"volleball","m.p. singh","a");
Query OK, 1 row affected (0.01 sec)
mysql> insert into sports values(1271,"volleball","m.p. singh","b");
Query OK, 1 row affected (0.03 sec)
mysql> insert into sports values(1434,"basket ball","i. malhotra","b");
Query OK, 1 row affected (0.02 sec)
mysql> insert into sports values(1461,"cricket","narendra","b");
Query OK, 1 row affected (0.03 sec)
mysql> insert into sports values(2328,"basket ball","i. malhotra","a");
Query OK, 1 row affected (0.03 sec)
mysql> insert into sports values(2371,"basket ball","i. malhotra","a");
Query OK, 1 row affected (0.02 sec)
mysql> insert into sports values(1271,"basket ball","i. malhotra","a");
Query OK, 1 row affected (0.03 sec)
mysql> insert into sports values(1434,"cricket","narendra","a");
Query OK, 1 row affected (0.02 sec)
mysql> insert into sports values(2328,"cricket","narendra","b");
Query OK, 1 row affected (0.03 sec)
mysql> insert into sports values(1364,"basket ball","i. malhotra","b");
Query OK, 1 row affected (0.03 sec)
mysql> select * from sports;

+----------+---------------+--------------------+---------+
| admno | game
| coachname | grade |
+----------+----------------+-------------------+---------+
| 1324 | cricket
| narendra
|a |
| 1364 | volleball | m.p. singh | a |
| 1271 | volleball | m.p. singh | b |
| 1434 | basket ball | i. malhotra | b |
| 1461 | cricket
| narendra
|b |
| 2328 | basket ball | i. malhotra | a |
| 2371 | basket ball | i. malhotra | a |
| 1271 | basket ball | i. malhotra | a |
| 1434 | cricket
| narendra
|a |
| 2328 | cricket
| narendra
|b |
| 1364 | basket ball | i. malhotra | b |
+----------+----------------+-------------------+-------+
11 rows in set (0.00 sec)
mysql> select max(class),min(class) from students;
+------------+------------+
| max(class) | min(class) |
+------------+------------+
|
12 |
10 |
+------------+------------+
1 row in set (0.02 sec)
mysql> select count(name) from students group by class;
+-------------+
| count(name) |
+-------------+
|
4|
|
3|
|
3|
+-------------+
3 rows in set (0.02 sec)
mysql> select count(name),class from students group by class;
+-------------+-------+
| count(name) | class |
+-------------+-------+
|
4 | 10 |
|
3 | 11 |
|
3 | 12 |
+-------------+-------+
3 rows in set (0.00 sec)
mysql> select count(name) from students where class=10;
+-------------+
| count(name) |
+-------------+
|
4|
+-------------+
1 row in set (0.00 sec)
mysql> select sp.admno,st.name,st.class,st.sec,st.rno,st.address,st.phone,sp.game from sports
sp,students st where
sp.game="cricket" and sp.admno=st.admno;

+---------+----------------------+--------+------+-------+-------------------------------+--------------------------+-----------+
| admno | name
| class | sec | rno | address
| phone
| game |
+---------+----------------------+--------+------+-------+-------------------------------+---------------------------+----------+
| 1324 | naresh sharma | 10 | a | 1 | 31, mohan nagar
| 435654
| cricket |
| 1461 | david dsouza | 11 | b | 1 | d-34, model town
| 243554, 98787665 | cricket |
| 1434 | varuna
| 12 | b | 21 | 69, rohini
| NULL
| cricket |
| 2328 | peter jones
| 10 | a | 10 | 21/32b, vishal enclave | 24356154
| cricket |
+---------+-----------------------+-------+------+------+---------------------------------+----------------------------+---------+
4 rows in set (0.00 sec)
mysql> select sp.admno,st.name,st.class,st.sec,st.rno from students st,sports sp where sp.grade="a" and
sp.adm
no=st.admno;
+-------+--------------------------+-------+------+------+
| admno | name
| class | sec | rno |
+-------+------------------------+-------+------+------+
| 1324 | naresh sharma | 10 | a | 1 |
| 1364 | subya akhtar | 11 | b | 13 |
| 2328 | peter jones
| 10 | a | 10 |
| 2371 | mohini mehta | 11 | c | 12 |
| 1271 | utkarsh madaan | 12 | c | 1 |
| 1434 | varuna
| 12 | b | 21 |
+-------+----------------+-------+------+------+
6 rows in set (0.02 sec)
mysql> select st.name,st.phone from students st,sports sp where sp.admno=st.admno;
+-----------------------+------------------+
| name
| phone
|
+-----------------------+------------------+
| naresh sharma | 435654
|
| subya akhtar
| NULL
|
| utkarsh madaan | 4356154
|
| varuna
| NULL
|
| david dsouza
| 243554, 98787665 |
| peter jones
| 24356154
|
| mohini mehta | 435654, 6765787 |
| utkarsh madaan | 4356154
|
| varuna
| NULL
|
| peter jones
| 24356154
|
| subya akhtar
| NULL
|
+------------------------+------------------+
11 rows in set (0.00 sec)
mysql> select distinct st.name,st.phone from students st,sports sp where sp.admno=st.admno;
+-----------------------+------------------+
| name
| phone
|
+-----------------------+------------------+
| naresh sharma | 435654
|
| subya akhtar | NULL
|
| utkarsh madaan | 4356154
|
| varuna
| NULL
|
| david dsouza | 243554, 98787665 |
| peter jones
| 24356154
|
| mohini mehta | 435654, 6765787 |
+-----------------------+------------------+
7 rows in set (0.00 sec)

mysql> select coachname,count(game) from sports group by coachname;


+------------------+-------------+
| coachname | count(game) |
+-------------------+-------------+
| i. malhotra |
5|
| m.p. singh |
2|
| narendra
|
4|
+-------------------+-------------+
3 rows in set (0.00 sec)
mysql> select st.name,st.phone from students st,(select admno from sports where coachname="nare
ndra" and grade="a") sp where sp.admno=st.admno;
+---------------+--------+
| name
| phone |
+---------------+--------+
| naresh sharma | 435654 |
| varuna
| NULL |
+---------------+--------+
2 rows in set (0.00 sec)
mysql> select class,sec,count(*) from students group by class,sec;
+-------+------+----------+
| class | sec | count(*) |
+-------+------+----------+
| 10 | a |
3|
| 10 | b |
1|
| 11 | b |
2|
| 11 | c |
1|
| 12 | b |
1|
| 12 | c |
2|
+-------+------+----------+
6 rows in set (0.02 sec)
mysql> select game,count(*) from sports group by game;
+-------------+----------+
| game
| count(*) |
+-------------+----------+
| basket ball |
5|
| cricket |
4|
| volleball |
2|
+-------------+----------+
3 rows in set (0.02 sec)

mysql> select game,name,address from students,sports where students.admno=sports.admno and grad


e="a";
+-------------+-----------------------+------------------------------+
| game
| name
| address
|
+-------------+-----------------------+-------------------------------+
| cricket | naresh sharma | 31, mohan nagar
|
| volleball | subya akhtar | 12, janak puri
|
| basket ball | peter jones
| 21/32b, vishal enclave |
| basket ball | mohini mehta | 37, raja garden
|
| basket ball | utkarsh madaan | c-32, punjabi bagh |
| cricket | varuna
| 69, rohini

+-------------+--------------------------+-------------------------------+
6 rows in set (0.00 sec)
mysql> select game from students,sports where students.admno=sports.admno and students.admno=14
34;
+-------------+
| game
|
+-------------+
| basket ball |
| cricket |
+-------------+
2 rows in set (0.00 sec)

QC Pg331
(c) A table named BILL has the following rows:
+-----------+-----------+------------+----------+
| order_num | cust_code | bill_date | bill_amt |
+-----------+-----------+------------+----------+
|
1 | c101
| 2010-08-02 |
2300 |
|
2 | c105
| 2010-08-02 |
5500 |
|
3 | c099
| 2010-08-23 |
3000 |
|
4 | c165
| 2010-09-24 |
6500 |
|
5 | c105
| 2010-09-24 |
1400 |
+-----------+-----------+------------+----------+
Write the output that will be displayed due to last SQL
SELECT statement;
START TRANSACTION;
INSERT INTO BILL VALUES(7,'C101','2010-09-03',5000);
UPDATE BILL SET BILL_AMT = BILL_AMT+500 WHERE ORDER_NUM
= 3;
SAVEPOINT A;
INSERT INTO BILL VALUES(8,'C97','2010-09-03',4500);
DELETE FROM BILL WHERE CUST_CODE='C105';

ROLLBACK TO A;
SELECT * FROM BILL;
+-----------+-----------+------------+----------+
| order_num | cust_code | bill_date | bill_amt |
+-----------+-----------+------------+----------+
|
1 | c101
| 2010-08-02 |
2300 |
|
2 | c105
| 2010-08-02 |
5500 |
|
3 | c099
| 2010-08-23 |
3500 |
|
4 | c165
| 2010-09-24 |
6500 |
|
5 | c105
| 2010-09-24 |
1400 |
|
7 | C101
| 2010-09-03 |
5000 |

Q 23 Pg521
IN A DATABASE THERE ARE TWO TABLES :
ITEMS
+-------+-----------------+-------+
| icode | iname
| price |
+-------+-----------------+-------+
|
101 | television
| 75000 |
|
202 | computer
| 42000 |
|
303 | refrigerator
| 90000 |
|
404 | washing machine | 27000 |
+-------+-----------------+-------+
BRAND
+-------+-------+
| icode | brand |
+-------+-------+
|
101 | sony |
|
202 | hp
|
|
303 | lg
|
|
303 | lg
|
|
404 | ifb
|
+-------+-------+
WRITE MySql QUARIES FOR THE FOLLOWING :
(i) To display ICode, Iname and corresponding Brands of those items,
whose price is between 20000 and 45000 (both values inclusive).
select icode,iname,brands from items,brand where price between
20000 and 45000;

(ii) To display icode, price and Bname of the item, which has iname as
"television"
select icode,price bname from items,brand where iname=
"televiosion";
(iii) To increase the price of all the items by 15%.
update items set price = 'price+15/100*price' ;

Potrebbero piacerti anche