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

Mysql

Haha

Uploaded by

iamkrishna2007
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)
7 views

Mysql

Haha

Uploaded by

iamkrishna2007
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/ 5

23-9-24

=======
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| q2 |
| test |
| zee |
+--------------------+
6 rows in set (0.02 sec)

mysql> use zee


Database changed
mysql> show tables;
+---------------+
| Tables_in_zee |
+---------------+
| marks |
| student |
+---------------+
2 rows in set (0.02 sec)

mysql> select * from marks ;


+---------+------+------+------+
| roll_no | sub1 | sub2 | sub3 |
+---------+------+------+------+
| 1 | 50 | 60 | 70 |
| 2 | 50 | 60 | 70 |
| 3 | 50 | 60 | 70 |
+---------+------+------+------+
3 rows in set (0.01 sec)

mysql> desc marks;


+---------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------+------+-----+---------+-------+
| roll_no | varchar(3) | YES | | NULL | |
| sub1 | int(3) | YES | | NULL | |
| sub2 | int(3) | YES | | NULL | |
| sub3 | int(3) | YES | | NULL | |
+---------+------------+------+-----+---------+-------+
4 rows in set (0.02 sec)

mysql> select * from student;


+---------+---------+-------+
| ROLL_NO | SNAME | MARKS |
+---------+---------+-------+
| 1 | krishna | NULL |
| 3 | juhil | NULL |
+---------+---------+-------+
2 rows in set (0.01 sec)

mysql> select * from marks ;


+---------+------+------+------+
| roll_no | sub1 | sub2 | sub3 |
+---------+------+------+------+
| 1 | 50 | 60 | 70 |
| 2 | 50 | 60 | 70 |
| 3 | 50 | 60 | 70 |
+---------+------+------+------+
3 rows in set (0.00 sec)

mysql> insert into student values (4, "prin", null);


Query OK, 1 row affected (0.00 sec)

mysql> select * from student;


+---------+---------+-------+
| ROLL_NO | SNAME | MARKS |
+---------+---------+-------+
| 1 | krishna | NULL |
| 3 | juhil | NULL |
| 4 | prin | NULL |
+---------+---------+-------+
3 rows in set (0.00 sec)

mysql> desc student;


+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| ROLL_NO | varchar(3) | NO | PRI | NULL | |
| SNAME | varchar(20) | YES | | NULL | |
| MARKS | int(3) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> select * from student;


+---------+---------+-------+
| ROLL_NO | SNAME | MARKS |
+---------+---------+-------+
| 1 | krishna | NULL |
| 3 | juhil | NULL |
| 4 | prin | NULL |
+---------+---------+-------+
3 rows in set (0.00 sec)

mysql> select * from student order by sname;


+---------+---------+-------+
| ROLL_NO | SNAME | MARKS |
+---------+---------+-------+
| 3 | juhil | NULL |
| 1 | krishna | NULL |
| 4 | prin | NULL |
+---------+---------+-------+
3 rows in set (0.00 sec)

mysql> select * from student order by sname desc;


+---------+---------+-------+
| ROLL_NO | SNAME | MARKS |
+---------+---------+-------+
| 4 | prin | NULL |
| 1 | krishna | NULL |
| 3 | juhil | NULL |
+---------+---------+-------+
3 rows in set (0.00 sec)
mysql> select * from student sname like "j%";
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'like "j
%"' at line 1
mysql> select * from student sname like 'j%';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'like 'j
%'' at line 1
mysql> select * from student where sname like 'j%';
+---------+-------+-------+
| ROLL_NO | SNAME | MARKS |
+---------+-------+-------+
| 3 | juhil | NULL |
+---------+-------+-------+
1 row in set (0.00 sec)

mysql> select * from student where sname like '%a';


+---------+---------+-------+
| ROLL_NO | SNAME | MARKS |
+---------+---------+-------+
| 1 | krishna | NULL |
+---------+---------+-------+
1 row in set (0.00 sec)

mysql> select * from student where sname like '%a%';


+---------+---------+-------+
| ROLL_NO | SNAME | MARKS |
+---------+---------+-------+
| 1 | krishna | NULL |
+---------+---------+-------+
1 row in set (0.00 sec)

mysql> select * from student where sname like '%s%';


+---------+---------+-------+
| ROLL_NO | SNAME | MARKS |
+---------+---------+-------+
| 1 | krishna | NULL |
+---------+---------+-------+
1 row in set (0.00 sec)

mysql> select * from student where sname like '%i%';


+---------+---------+-------+
| ROLL_NO | SNAME | MARKS |
+---------+---------+-------+
| 1 | krishna | NULL |
| 3 | juhil | NULL |
| 4 | prin | NULL |
+---------+---------+-------+
3 rows in set (0.00 sec)

mysql> select * from student where sname like 'j__';


Empty set (0.00 sec)

mysql> select * from student where sname like 'j____';


+---------+-------+-------+
| ROLL_NO | SNAME | MARKS |
+---------+-------+-------+
| 3 | juhil | NULL |
+---------+-------+-------+
1 row in set (0.00 sec)

mysql> select * from student where sname like 'j_%';


+---------+-------+-------+
| ROLL_NO | SNAME | MARKS |
+---------+-------+-------+
| 3 | juhil | NULL |
+---------+-------+-------+
1 row in set (0.00 sec)

mysql> select * from student where sname like '_u%';


+---------+-------+-------+
| ROLL_NO | SNAME | MARKS |
+---------+-------+-------+
| 3 | juhil | NULL |
+---------+-------+-------+
1 row in set (0.00 sec)

mysql> select * from student where sname like '__i%';


+---------+---------+-------+
| ROLL_NO | SNAME | MARKS |
+---------+---------+-------+
| 1 | krishna | NULL |
| 4 | prin | NULL |
+---------+---------+-------+
2 rows in set (0.00 sec)

mysql> select * from marks ;


+---------+------+------+------+
| roll_no | sub1 | sub2 | sub3 |
+---------+------+------+------+
| 1 | 50 | 60 | 70 |
| 2 | 50 | 60 | 70 |
| 3 | 50 | 60 | 70 |
+---------+------+------+------+
3 rows in set (0.00 sec)

mysql> select roll_no,sub1,sub2,sub3, sub1+sub2+sub3 as total from marks ;


+---------+------+------+------+-------+
| roll_no | sub1 | sub2 | sub3 | total |
+---------+------+------+------+-------+
| 1 | 50 | 60 | 70 | 180 |
| 2 | 50 | 60 | 70 | 180 |
| 3 | 50 | 60 | 70 | 180 |
+---------+------+------+------+-------+
3 rows in set (0.00 sec)

mysql> select roll_no,sub1,sub2,sub3, sub1+sub2+sub3 as total, total/3 from marks


;
ERROR 1054 (42S22): Unknown column 'total' in 'field list'
mysql> select roll_no,sub1,sub2,sub3, sub1+sub2+sub3 as total, sub1+sub2+sub3/3
from marks ;
+---------+------+------+------+-------+------------------+
| roll_no | sub1 | sub2 | sub3 | total | sub1+sub2+sub3/3 |
+---------+------+------+------+-------+------------------+
| 1 | 50 | 60 | 70 | 180 | 133.3333 |
| 2 | 50 | 60 | 70 | 180 | 133.3333 |
| 3 | 50 | 60 | 70 | 180 | 133.3333 |
+---------+------+------+------+-------+------------------+
3 rows in set (0.00 sec)

mysql> select roll_no,sub1,sub2,sub3, sub1+sub2+sub3 as total, sub1+sub2+sub3/3 as


avg from marks ;
+---------+------+------+------+-------+----------+
| roll_no | sub1 | sub2 | sub3 | total | avg |
+---------+------+------+------+-------+----------+
| 1 | 50 | 60 | 70 | 180 | 133.3333 |
| 2 | 50 | 60 | 70 | 180 | 133.3333 |
| 3 | 50 | 60 | 70 | 180 | 133.3333 |
+---------+------+------+------+-------+----------+
3 rows in set (0.00 sec)

mysql> select roll_no,sub1,sub2,sub3, sub1+sub2+sub3 as total, sub1+sub2+sub3/3 as


avg from marks ;

mysql> select * from marks ;


+---------+------+------+------+
| roll_no | sub1 | sub2 | sub3 |
+---------+------+------+------+
| 1 | 50 | 60 | 70 |
| 2 | 50 | 60 | 70 |
| 3 | 50 | 60 | 70 |
+---------+------+------+------+
3 rows in set (0.00 sec)

mysql> select * from student;


+---------+---------+-------+
| ROLL_NO | SNAME | MARKS |
+---------+---------+-------+
| 1 | krishna | NULL |
| 3 | juhil | NULL |
| 4 | prin | NULL |
+---------+---------+-------+
3 rows in set (0.00 sec)

mysql> select s.roll_no, s.sname, m.sub1,m.sub2,m.sub3, m.sub1+m.sub2+m.sub3 as


total from student s , marks m where s.roll_no=m.roll_no;
+---------+---------+------+------+------+-------+
| roll_no | sname | sub1 | sub2 | sub3 | total |
+---------+---------+------+------+------+-------+
| 1 | krishna | 50 | 60 | 70 | 180 |
| 3 | juhil | 50 | 60 | 70 | 180 |
+---------+---------+------+------+------+-------+
2 rows in set (0.00 sec)

You might also like