documentok

Download Documentok

If you can't read please download the document

Upload: ujjwal

Post on 24-Jan-2016

212 views

Category:

Documents


0 download

DESCRIPTION

ok

TRANSCRIPT

mysql> use ujjwal;Database changedmysql> CREATE TABLE teachers -> ( name char(30), -> deptt char(10), -> age integer, -> exp integer, -> salary integer);Query OK, 0 rows affected (0.26 sec)mysql> INSERT INTO teachers -> VALUES("amit","maths",34,6,50000);Query OK, 1 row affected (0.07 sec)mysql> INSERT INTO teachers -> VALUES("sakshi","chemistry",43,10,65000);Query OK, 1 row affected (0.03 sec)mysql> INSERT INTO teachers -> VALUES("shubhanshu","physics",36,8,65000);Query OK, 1 row affected (0.03 sec)mysql> INSERT INTO teachers -> VALUES("janvi","cs",35,9,80000);Query OK, 1 row affected (0.02 sec)mysql> INSERT INTO teachers -> VALUES("bala","english",34,8,55000);Query OK, 1 row affected (0.02 sec)mysql> SELECT*FROM teachers -> WHERE exp>5;+------------+-----------+------+------+--------+| name | deptt | age | exp | salary |+------------+-----------+------+------+--------+| amit | maths | 34 | 6 | 50000 || sakshi | chemistry | 43 | 10 | 65000 || shubhanshu | physics | 36 | 8 | 65000 || janvi | cs | 35 | 9 | 80000 || bala | english | 34 | 8 | 55000 |+------------+-----------+------+------+--------+5 rows in set (0.03 sec)mysql> UPDATE teachers -> SET salary=salary+salary*0.2 -> WHERE exp BETWEEN 9 AND 12;Query OK, 2 rows affected (0.06 sec)Rows matched: 2 Changed: 2 Warnings: 0mysql> SELECT*FROM teachers -> ;+------------+-----------+------+------+--------+| name | deptt | age | exp | salary |+------------+-----------+------+------+--------+| amit | maths | 34 | 6 | 50000 || sakshi | chemistry | 43 | 10 | 78000 || shubhanshu | physics | 36 | 8 | 65000 || janvi | cs | 35 | 9 | 96000 || bala | english | 34 | 8 | 55000 |+------------+-----------+------+------+--------+5 rows in set (0.00 sec)mysql> SELECT* FROM teachers;+------------+-----------+------+------+--------+| name | deptt | age | exp | salary |+------------+-----------+------+------+--------+| amit | maths | 34 | 6 | 50000 || sakshi | chemistry | 43 | 10 | 78000 || shubhanshu | physics | 36 | 8 | 65000 || janvi | cs | 35 | 9 | 96000 || bala | english | 34 | 8 | 55000 |+------------+-----------+------+------+--------+5 rows in set (0.00 sec)mysql> INSERT INTO teachers -> VALUES("kirti","maths",58,25,80000);Query OK, 1 row affected (0.06 sec)mysql> INSERT INTO teachers -> VALUES("smriti","maths",43,16,78000);Query OK, 1 row affected (0.02 sec)mysql> INSERT INTO teachers -> VALUES("vyom","cs",54,22,80000);Query OK, 1 row affected (0.02 sec)mysql> SELECT*FROM teachers -> WHERE deptt=(SELECT deptt FROM teachers WHERE name="kirti");+--------+-------+------+------+--------+| name | deptt | age | exp | salary |+--------+-------+------+------+--------+| amit | maths | 34 | 6 | 50000 || kirti | maths | 58 | 25 | 80000 || smriti | maths | 43 | 16 | 78000 |+--------+-------+------+------+--------+3 rows in set (0.01 sec)mysql> ALTER TABLE teachers -> ADD sex char(1);Query OK, 8 rows affected (0.30 sec)Records: 8 Duplicates: 0 Warnings: 0mysql> SELECT count(*),max(exp) FROM teachers -> GROUP BY deptt -> HAVING min(age)>30;+----------+----------+| count(*) | max(exp) |+----------+----------+| 1 | 10 || 2 | 22 || 1 | 8 || 3 | 25 || 1 | 8 |+----------+----------+5 rows in set (0.04 sec)mysql> SELECT deptt,count(*),max(exp) FROM teachers -> GROUP BY deptt -> HAVING min(age)>30;+-----------+----------+----------+| deptt | count(*) | max(exp) |+-----------+----------+----------+| chemistry | 1 | 10 || cs | 2 | 22 || english | 1 | 8 || maths | 3 | 25 || physics | 1 | 8 |+-----------+----------+----------+5 rows in set (0.00 sec)