-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQueries.txt
389 lines (314 loc) · 13.7 KB
/
Queries.txt
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
mysql> use test;
Database changed
mysql> tee /tmp/testspool.txt;
Logging to file '/tmp/testspool.txt;'
mysql> select name from emp;
mysql> notee
select emp.ename,l.empleave from employee emp join empleaves l on l.empid = emp.eid;
SELECT DEP.DEPNAME,EMP.ENAME FROM DEPARTMENT DEP JOIN EMPLOYEE EMP ON DEP.DID = EMP.DEPID;
select ename from employee where eid = 1;
select depname from department where did > 1 AND did < 4;
select ename from employee order by ename asc;
select * from empleaves where empleave IS NOT NULL;
select MAX(l.empleave) AS Maximum_Leaves,e.ename from empleaves l join employee e on l.empid = e.eid;
select count(*) from employee where eid > 2;
SELECT AVG(DEPID) FROM EMPLOYEE;
select ename,email,eid,depid from employee where ename like "s%";
select count(did),depname,dsc from department group by depname;
mysql> use emsdatabase;
Database changed
mysql> select emp.ename,l.empleave from employee emp join empleaves l on l.empid = emp.eid;
+-----------+----------+
| ename | empleave |
+-----------+----------+
| SHREYANSH | 3 |
| PRANJAY | 6 |
| SUBHO | 1 |
| SHREYANSH | 8 |
| PRANJAY | 3 |
+-----------+----------+
5 rows in set (0.02 sec)
mysql> SELECT DEP.DEPNAME,EMP.ENAME FROM DEPARTMENT DEP JOIN EMPLOYEE EMP ON DEP.DID = EMP.DEPID;
+----------------+-------------+
| DEPNAME | ENAME |
+----------------+-------------+
| FINANCE | PRANJAY |
| GRAPHICS | SHREYANSH |
| TECHNICAL | NISHANT |
| HUMAN RESOURCE | SUBHO |
| HARDWARE | ANKITA |
| GRAPHICS | ankittiwari |
| TECHNICAL | rohan |
| HARDWARE | sathwik |
| HUMAN RESOURCE | akash |
| HARDWARE | aman |
+----------------+-------------+
10 rows in set (0.00 sec)
mysql> select ename from employee where eid = 1;
+---------+
| ename |
+---------+
| PRANJAY |
+---------+
1 row in set (0.00 sec)
mysql> select depname from department where did > 1 AND did < 4;
+----------------+
| depname |
+----------------+
| GRAPHICS |
| HUMAN RESOURCE |
+----------------+
2 rows in set (0.00 sec)
mysql> select ename from employee order by ename asc;
+-------------+
| ename |
+-------------+
| akash |
| aman |
| ANKITA |
| ankittiwari |
| NISHANT |
| PRANJAY |
| rohan |
| sathwik |
| SHREYANSH |
| SUBHO |
+-------------+
10 rows in set (0.00 sec)
mysql> select * from empleaves where empleave IS NOT NULL;
+-----+----------+-------+
| lid | empleave | empid |
+-----+----------+-------+
| 1 | 3 | 2 |
| 2 | 6 | 1 |
| 3 | 1 | 4 |
| 4 | 8 | 2 |
| 5 | 3 | 1 |
+-----+----------+-------+
5 rows in set (0.00 sec)
mysql> select MAX(l.empleave) AS Maximum_Leaves,e.ename from empleaves l join employee e on l.empid = e.eid;
+----------------+-----------+
| Maximum_Leaves | ename |
+----------------+-----------+
| 8 | SHREYANSH |
+----------------+-----------+
1 row in set (0.00 sec)
mysql> select count(*) from employee where eid > 2;
+----------+
| count(*) |
+----------+
| 8 |
+----------+
1 row in set (0.00 sec)
mysql> SELECT AVG(DEPID) FROM EMPLOYEE;
+------------+
| AVG(DEPID) |
+------------+
| 3.4000 |
+------------+
1 row in set (0.00 sec)
mysql> select ename,email,eid,depid from employee where ename like "s%";
+-----------+----------------+-----+-------+
| ename | email | eid | depid |
+-----------+----------------+-----+-------+
| SHREYANSH | [email protected] | 2 | 2 |
| SUBHO | [email protected] | 4 | 3 |
| sathwik | [email protected] | 8 | 5 |
+-----------+----------------+-----+-------+
3 rows in set (0.00 sec)
mysql> select count(did),depname,dsc from department group by depname;
+------------+----------------+-----------------------+
| count(did) | depname | dsc |
+------------+----------------+-----------------------+
| 1 | FINANCE | DEAL WITH FINANCE |
| 1 | GRAPHICS | DEAL WITH GRAPHICS |
| 1 | HUMAN RESOURCE | DEAL WITH HR |
| 1 | TECHNICAL | DEAL WITH TECH |
| 1 | HARDWARE | DEAL WITH HARDWARE |
| 1 | DEVELOPMENT | DEAL WITH DEV TECH |
| 1 | MARKETING | DEALS WITH PROMOTIONS |
| 1 | ANALYTICS | DEALS WITH STATS |
| 1 | CONTENT | DEALS WITH CONTENT |
| 1 | SALES | DEALS WITH SALES |
+------------+----------------+-----------------------+
10 rows in set (0.00 sec)
mysql> select sum(depid), ename,pid,count(eid) from employee;
ERROR 1054 (42S22): Unknown column 'pid' in 'field list'
mysql> select sum(depid), ename,posid,eid from employee;
+------------+---------+-------+------+
| sum(depid) | ename | posid | eid |
+------------+---------+-------+------+
| 34 | PRANJAY | 2 | 1 |
+------------+---------+-------+------+
1 row in set (0.00 sec)
mysql> select ename where depid = 2;
ERROR 1054 (42S22): Unknown column 'ename' in 'field list'
mysql> select ename from employee where depid = 2;
+-------------+
| ename |
+-------------+
| SHREYANSH |
| ankittiwari |
+-------------+
2 rows in set (0.00 sec)
mysql> select sum(depid), ename,pid,count(eid) from employee;
ERROR 1054 (42S22): Unknown column 'pid' in 'field list'
mysql> select sum(depid), ename,posid,eid from employee;
+------------+---------+-------+------+
| sum(depid) | ename | posid | eid |
+------------+---------+-------+------+
| 34 | PRANJAY | 2 | 1 |
+------------+---------+-------+------+
1 row in set (0.00 sec)
mysql> select sum(depid), ename,posid,eid from employee;
+------------+---------+-------+------+
| sum(depid) | ename | posid | eid |
+------------+---------+-------+------+
| 34 | PRANJAY | 2 | 1 |
+------------+---------+-------+------+
1 row in set (0.00 sec)
mysql> select count(username) from login;
+-----------------+
| count(username) |
+-----------------+
| 5 |
+-----------------+
1 row in set (0.02 sec)
mysql> select email from employee where email like "%s%"
-> ;
+----------------+
| email |
+----------------+
+----------------+
6 rows in set (0.00 sec)
mysql> select email from employee where email like "%s%";
+----------------+
| email |
+----------------+
+----------------+
6 rows in set (0.00 sec)
mysql> select pid,pname,dsc from pos;
ERROR 1054 (42S22): Unknown column 'dsc' in 'field list'
mysql> desc pos;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| pid | int | NO | PRI | NULL | |
| pname | varchar(25) | YES | | NULL | |
| posting | varchar(25) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
3 rows in set (0.02 sec)
mysql> select pid,pname,posting from pos where posting = "chennai";
+-----+---------+---------+
| pid | pname | posting |
+-----+---------+---------+
| 1 | MANAGER | CHENNAI |
+-----+---------+---------+
1 row in set (0.00 sec)
mysql> select email from employee where email like "%s%";
+----------------+
| email |
+----------------+
+----------------+
6 rows in set (0.00 sec)
mysql> select p.pid,p.pname,p.posting,e.ename,e.email from pos p join employee e on p.pid = e.posid;
+-----+---------------+----------+-------------+-------------------------+
| pid | pname | posting | ename | email |
+-----+---------------+----------+-------------+-------------------------+
| 2 | DIRECTOR | MUMBAI | PRANJAY | [email protected] |
| 3 | MANAGER | DELHI | SHREYANSH | [email protected] |
| 1 | MANAGER | CHENNAI | NISHANT | [email protected] |
| 4 | SR. DEVELOPER | AGRA | SUBHO | [email protected] |
| 2 | DIRECTOR | MUMBAI | ANKITA | [email protected] |
| 2 | DIRECTOR | MUMBAI | ankittiwari | [email protected] |
| 6 | TECH LEAD | JABALPUR | rohan | [email protected] |
| 6 | TECH LEAD | JABALPUR | sathwik | [email protected] |
| 2 | DIRECTOR | MUMBAI | akash | [email protected] |
| 1 | MANAGER | CHENNAI | aman | [email protected] |
+-----+---------------+----------+-------------+-------------------------+
10 rows in set (0.00 sec)
mysql> select p.pid,p.pname,p.posting,e.ename,e.email from pos p join employee e on p.pid = e.posid where p.pid >2 group by e.ename;
+-----+---------------+----------+-----------+-----------------+
| pid | pname | posting | ename | email |
+-----+---------------+----------+-----------+-----------------+
| 3 | MANAGER | DELHI | SHREYANSH | [email protected] |
| 4 | SR. DEVELOPER | AGRA | SUBHO | [email protected] |
| 6 | TECH LEAD | JABALPUR | rohan | [email protected] |
| 6 | TECH LEAD | JABALPUR | sathwik | [email protected] |
+-----+---------------+----------+-----------+-----------------+
4 rows in set (0.00 sec)
mysql> select p.pid,p.pname,p.posting,e.ename,e.email from pos p join employee e on p.pid = e.posid where p.pid >=1 group by p.pname;
+-----+---------------+----------+-----------+-------------------------+
| pid | pname | posting | ename | email |
+-----+---------------+----------+-----------+-------------------------+
| 2 | DIRECTOR | MUMBAI | PRANJAY | [email protected] |
| 3 | MANAGER | DELHI | SHREYANSH | [email protected] |
| 4 | SR. DEVELOPER | AGRA | SUBHO | [email protected] |
| 6 | TECH LEAD | JABALPUR | rohan | [email protected] |
+-----+---------------+----------+-----------+-------------------------+
4 rows in set (0.00 sec)
mysql> select p.pid,p.pname,p.posting,e.ename,e.email from pos p join employee e on p.pid = e.posid group by p.pname;
+-----+---------------+----------+-----------+-------------------------+
| pid | pname | posting | ename | email |
+-----+---------------+----------+-----------+-------------------------+
| 2 | DIRECTOR | MUMBAI | PRANJAY | [email protected] |
| 3 | MANAGER | DELHI | SHREYANSH | [email protected] |
| 4 | SR. DEVELOPER | AGRA | SUBHO | [email protected] |
| 6 | TECH LEAD | JABALPUR | rohan | [email protected] |
+-----+---------------+----------+-----------+-------------------------+
4 rows in set (0.00 sec)
mysql> select d.did,p.depname,d.dsc,e.ename,e.email from department d join employee e on d.did = e.depid group by p.pname;
ERROR 1054 (42S22): Unknown column 'p.depname' in 'field list'
mysql> select d.did,p.depname,d.dsc,e.ename,e.email from department d join employee e on d.did = e.depid group by d.depname;
ERROR 1054 (42S22): Unknown column 'p.depname' in 'field list'
mysql> select d.did,d.depname,d.dsc,e.ename,e.email from department d join employee e on d.did = e.depid group by d.depname;
+-----+----------------+--------------------+-----------+-------------------------+
| did | depname | dsc | ename | email |
+-----+----------------+--------------------+-----------+-------------------------+
| 1 | FINANCE | DEAL WITH FINANCE | PRANJAY | [email protected] |
| 2 | GRAPHICS | DEAL WITH GRAPHICS | SHREYANSH | [email protected] |
| 4 | TECHNICAL | DEAL WITH TECH | NISHANT | [email protected] |
| 3 | HUMAN RESOURCE | DEAL WITH HR | SUBHO | [email protected] |
| 5 | HARDWARE | DEAL WITH HARDWARE | ANKITA | [email protected] |
+-----+----------------+--------------------+-----------+-------------------------+
5 rows in set (0.00 sec)
mysql> select d.did,d.depname,d.dsc,e.ename,e.email from department d join employee e on d.did = e.depid group by d.depname;
+-----+----------------+--------------------+-----------+-------------------------+
| did | depname | dsc | ename | email |
+-----+----------------+--------------------+-----------+-------------------------+
| 1 | FINANCE | DEAL WITH FINANCE | PRANJAY | [email protected] |
| 2 | GRAPHICS | DEAL WITH GRAPHICS | SHREYANSH | [email protected] |
| 4 | TECHNICAL | DEAL WITH TECH | NISHANT | [email protected] |
| 3 | HUMAN RESOURCE | DEAL WITH HR | SUBHO | [email protected] |
| 5 | HARDWARE | DEAL WITH HARDWARE | ANKITA | [email protected] |
+-----+----------------+--------------------+-----------+-------------------------+
5 rows in set (0.00 sec)
mysql> select p.pid,p.pname,p.posting,e.ename,e.email from pos p join employee e on p.pid = e.posid group by p.pname;
+-----+---------------+----------+-----------+-------------------------+
| pid | pname | posting | ename | email |
+-----+---------------+----------+-----------+-------------------------+
| 2 | DIRECTOR | MUMBAI | PRANJAY | [email protected] |
| 3 | MANAGER | DELHI | SHREYANSH | [email protected] |
| 4 | SR. DEVELOPER | AGRA | SUBHO | [email protected] |
| 6 | TECH LEAD | JABALPUR | rohan | [email protected] |
+-----+---------------+----------+-----------+-------------------------+
4 rows in set (0.00 sec)
mysql>