-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAll_operations.sql
200 lines (178 loc) · 4.57 KB
/
All_operations.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
Problem Statement: Perform different operations on student and dept table.
Name:- Jadhav Swapnil Jalindar
Batch:- AS4
Rno:- 67
PRN no. :- UCS21M1067
*/
mysql> use Operations;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select *from student;
+------+---------+---------+
| rno | name | sfees |
+------+---------+---------+
| 1 | kaushal | 1234.56 |
| 2 | abhi | 4534.67 |
| 3 | sagar | 2321.78 |
| 4 | adesh | 5653.45 |
| 5 | tushar | 700.00 |
| 6 | om | 1000.99 |
| 7 | krishna | 2223.67 |
+------+---------+---------+
7 rows in set (0.00 sec)
mysql> insert into student values(8,'sumit',1298.91);
Query OK, 1 row affected (0.05 sec)
mysql> delete from student where rno=3;
Query OK, 1 row affected (0.08 sec)
mysql> update student set sfees=2001.63 where name='om';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select *from student;
+------+---------+---------+
| rno | name | sfees |
+------+---------+---------+
| 1 | kaushal | 1234.56 |
| 2 | abhi | 4534.67 |
| 4 | adesh | 5653.45 |
| 5 | tushar | 700.00 |
| 6 | om | 2001.63 |
| 7 | krishna | 2223.67 |
| 8 | sumit | 1298.91 |
+------+---------+---------+
7 rows in set (0.01 sec)
mysql> select count(rno) from student;
+------------+
| count(rno) |
+------------+
| 7 |
+------------+
1 row in set (0.00 sec)
mysql> select count(*) from student;
+----------+
| count(*) |
+----------+
| 7 |
+----------+
1 row in set (0.05 sec)
mysql> select avg(rno) from student;
+----------+
| avg(rno) |
+----------+
| 4.7143 |
+----------+
1 row in set (0.00 sec)
mysql> select avg(sfees) from student;
+-------------+
| avg(sfees) |
+-------------+
| 2520.984305 |
+-------------+
1 row in set (0.00 sec)
mysql> select min(sfees) from student;
+------------+
| min(sfees) |
+------------+
| 700.00 |
+------------+
1 row in set (0.00 sec)
mysql> select max(sfees) from student;
+------------+
| max(sfees) |
+------------+
| 5653.45 |
+------------+
1 row in set (0.00 sec)
mysql> select name from student where sfees=(select max(sfees) from student);
+-------+
| name |
+-------+
| adesh |
+-------+
1 row in set (1.25 sec)
mysql> select name from student where sfees=(select min(sfees) from student);
+--------+
| name |
+--------+
| tushar |
+--------+
1 row in set (0.00 sec)
mysql> select *from student;
+------+---------+---------+
| rno | name | sfees |
+------+---------+---------+
| 1 | kaushal | 1234.56 |
| 2 | abhi | 4534.67 |
| 4 | adesh | 5653.45 |
| 5 | tushar | 700.00 |
| 6 | om | 2001.63 |
| 7 | krishna | 2223.67 |
| 8 | sumit | 1298.91 |
+------+---------+---------+
7 rows in set (0.00 sec)
mysql> create table dept(rno int(3),dno int(3),dname varchar(20));
Query OK, 0 rows affected, 2 warnings (0.38 sec)
mysql> select *from dept;
+------+------+-------+
| rno | dno | dname |
+------+------+-------+
| 1 | 10 | comp |
| 2 | 11 | mech |
| 3 | 12 | civil |
| 4 | 13 | ece |
| 5 | 14 | mtx |
| 7 | 16 | it |
| 8 | 17 | str |
+------+------+-------+
7 rows in set (0.00 sec)
mysql> select student.name, dept.dname from student inner join dept on dept.rno=student.rno;
+---------+-------+
| name | dname |
+---------+-------+
| kaushal | comp |
| abhi | mech |
| adesh | ece |
| tushar | mtx |
| krishna | it |
| sumit | str |
+---------+-------+
6 rows in set (0.00 sec)
mysql> select student.name, dept.dname from student left join dept on dept.rno=student.rno;
+---------+-------+
| name | dname |
+---------+-------+
| kaushal | comp |
| abhi | mech |
| adesh | ece |
| tushar | mtx |
| om | NULL |
| krishna | it |
| sumit | str |
+---------+-------+
7 rows in set (0.00 sec)
mysql> select student.name, dept.dname from student right join dept on dept.rno=student.rno;
+---------+-------+
| name | dname |
+---------+-------+
| kaushal | comp |
| abhi | mech |
| NULL | civil |
| adesh | ece |
| tushar | mtx |
| krishna | it |
| sumit | str |
+---------+-------+
7 rows in set (0.00 sec)
mysql> create view sfees as select *from student where sfees<=1500;
Query OK, 0 rows affected (0.10 sec)
mysql> select *from sfees;
+------+---------+---------+
| rno | name | sfees |
+------+---------+---------+
| 1 | kaushal | 1234.56 |
| 5 | tushar | 700.00 |
| 8 | sumit | 1298.91 |
+------+---------+---------+
3 rows in set (0.00 sec)
mysql>