-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMYSQL QUERIES ON SAMSTHA STORE MANA.sql
396 lines (396 loc) · 16.3 KB
/
MYSQL QUERIES ON SAMSTHA STORE MANA.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
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
MYSQL QUERIES ON SAMSTHA STORE MANAGEMENT SYSTEM
1.Describe &Show all tables
mysql> use trial;
Database changed
mysql> show tables;
+-----------------+
| Tables_in_trial |
+-----------------+
| admin |
| customer |
| log |
| product |
| transaction |
+-----------------+
5 rows in set (0.00 sec)
mysql> desc admin;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| Admin_id | int | NO | PRI | NULL | |
| Username | varchar(30) | NO | | NULL | |
| Password | varchar(15) | NO | | NULL | |
+----------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> desc customer;
+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| roll_number | varchar(10) | NO | PRI | NULL | |
| Student_name | varchar(255) | YES | | NULL | |
| phno | varchar(10) | YES | | NULL | |
| department | varchar(255) | YES | | NULL | |
+--------------+--------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> desc log;
+-------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+----------------+
| sr_no | int | NO | PRI | NULL | auto_increment |
| roll_number | varchar(10) | YES | | NULL | |
| phno | varchar(10) | YES | | NULL | |
+-------------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
mysql> desc product;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| P_Id | int | NO | PRI | NULL | |
| P_Name | varchar(50) | NO | | NULL | |
| Price | int | NO | | NULL | |
| Category | varchar(50) | NO | | NULL | |
| Quantity | int | NO | | NULL | |
| Admin_id | int | YES | MUL | NULL | |
+----------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
mysql> desc transaction;
+-------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+----------------+
| t_id | int | NO | PRI | NULL | auto_increment |
| P_Id | int | NO | | NULL | |
| P_name | varchar(50) | NO | | NULL | |
| quantity | int | NO | | NULL | |
| time_date | date | NO | | NULL | |
| Total_Price | decimal(10,2) | YES | | NULL | |
| roll_number | varchar(10) | YES | | NULL | |
+-------------+---------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
mysql> select* from admin;
+----------+------------------+----------+
| Admin_id | Username | Password |
+----------+------------------+----------+
| 101 | Divya Pardeshi | Div123 |
| 102 | Divya Ganeshwala | Div456 |
| 103 | Rutuja Dhirde | Rutu456 |
+----------+------------------+----------+
3 rows in set (0.00 sec)
mysql> select * from customer;
+-------------+---------------+------------+------------+
| roll_number | Student_name | phno | department |
+-------------+---------------+------------+------------+
| 1 | Rose | NULL | NULL |
| 2 | Harry | NULL | NULL |
| 3 | Divya | 2 | computer |
| uce2022447 | Khyati shetty | 6666677777 | computer |
| uce2022448 | k | 6666655555 | computer |
| uce2022451 | Shrutika | 5151515151 | computer |
| uce2022452 | avani | 5252525252 | computer |
| uce2022453 | rutuja d | 5555566667 | computer |
| uce2022454 | bhakti | 5454545454 | computer |
| uce2022455 | divya p | 9890200573 | computer |
| uce2022456 | divya | 776040097 | computer |
| uce2022457 | ketaki dixit | 5757575757 | computer |
+-------------+---------------+------------+------------+
12 rows in set (0.00 sec)
mysql> select * from log;
+-------+-------------+------------+
| sr_no | roll_number | phno |
+-------+-------------+------------+
| 1 | uce2022447 | 6666677777 |
| 2 | uce2022447 | 6666677777 |
| 3 | uce2022447 | 6666677777 |
| 4 | uce2022447 | 6666677777 |
| 5 | uce2022447 | 6666677777 |
| 6 | uce2022447 | 6666677777 |
| 7 | uce2022447 | 6666677777 |
| 8 | uce2022447 | 6666677777 |
| 9 | uce2022447 | 6666677777 |
| 10 | uce2022447 | 6666677777 |
| 11 | uce2022447 | 6666677777 |
| 12 | uce2022447 | 6666677777 |
| 13 | uce2022447 | 6666677777 |
| 14 | uce2022447 | 6666677777 |
| 15 | uce2022447 | 6666677777 |
| 16 | uce2022447 | 6666677777 |
| 17 | uce2022447 | 6666677777 |
| 18 | uce2022447 | 6666677777 |
| 19 | uce2022447 | 6666677777 |
| 20 | uce2022447 | 6666677777 |
| 21 | uce2022447 | 6666677777 |
| 22 | uce2022447 | 6666677777 |
| 23 | uce2022447 | 6666677777 |
| 24 | uce2022456 | 6666677777 |
| 25 | uce2022447 | 6666677777 |
| 26 | UCE2022447 | 6666677777 |
| 27 | uce2022447 | 6666677777 |
| 28 | uce2022451 | 5151515151 |
| 29 | uce2022454 | 5454545454 |
| 30 | uce2022457 | 5757575757 |
| 31 | uce2022447 | 4747474747 |
| 32 | uce2022447 | 6666677777 |
| 33 | uce2022447 | 6666677777 |
| 34 | uce2022447 | 6666677777 |
| 35 | uce2022447 | 6666677777 |
| 36 | uce2022447 | 6666677777 |
| 37 | UCE2022447 | 6666677777 |
| 38 | uce2022447 | 6666677777 |
| 39 | uce2022447 | 6666677777 |
| 40 | uce2022447 | 6666677777 |
+-------+-------------+------------+
40 rows in set (0.00 sec)
mysql> select * from product;
+------+--------------------------+-------+------------+----------+----------+
| P_Id | P_Name | Price | Category | Quantity | Admin_id |
+------+--------------------------+-------+------------+----------+----------+
| 1 | Plain sheet | 1 | stationery | 100 | 101 |
| 2 | One sided Ruled sheet | 2 | stationery | 100 | 102 |
| 3 | Double sided Ruled sheet | 2 | stationery | 100 | 102 |
| 4 | Index sheet | 2 | stationery | 100 | 102 |
| 5 | Graph paper | 3 | stationery | 100 | 103 |
| 6 | Logarithmic Graph paper | 3 | stationery | 100 | 103 |
| 7 | FY file | 1 | stationery | 100 | 103 |
| 8 | SY file | 1 | stationery | 100 | 103 |
| 9 | TY file | 1 | stationery | 100 | 103 |
| 10 | BTech file | 1 | stationery | 100 | 103 |
+------+--------------------------+-------+------------+----------+----------+
10 rows in set (0.00 sec)
mysql> select * from transaction;
+------+------+---------------+----------+------------+-------------+-------------+
| t_id | P_Id | P_name | quantity | time_date | Total_Price | roll_number |
+------+------+---------------+----------+------------+-------------+-------------+
| 1 | 1 | Index Sheets | 2 | 2024-04-02 | 10.00 | NULL |
| 2 | 2 | Ruled Sheets | 3 | 2024-04-02 | 30.00 | NULL |
| 3 | 3 | Plain Sheets | 5 | 2024-04-02 | 25.00 | NULL |
| 4 | 1 | Index Sheets | 1 | 2024-04-02 | 5.00 | NULL |
| 5 | 1 | Index Sheets | 12 | 2024-04-04 | 60.00 | NULL |
| 6 | 1 | Index Sheets | 12 | 2024-04-04 | 60.00 | NULL |
| 7 | 1 | Index Sheets | 12 | 2024-04-04 | 60.00 | NULL |
| 8 | 1 | Index Sheets | 12 | 2024-04-04 | 60.00 | NULL |
| 9 | 1 | Index Sheets | 12 | 2024-04-04 | 60.00 | NULL |
| 11 | 1 | Index Sheets | 23 | 2024-04-05 | 69.00 | uce2022456 |
| 12 | 1 | Index Sheets | 23 | 2024-04-05 | 69.00 | uce2022456 |
| 13 | 1 | Index Sheets | 23 | 2024-04-05 | 69.00 | uce2022456 |
| 14 | 1 | Index Sheets | 23 | 2024-04-05 | 69.00 | 1 |
| 16 | 1 | Index Sheets | 15 | 2024-04-05 | 45.00 | uce2022455 |
| 23 | 2 | Ruled Sheets | 2 | 2024-04-07 | 20.00 | 111 |
| 24 | 1 | plain sheets | 4 | 2024-04-07 | 12.00 | 111 |
| 25 | 1 | plain sheets | 4 | 2024-04-07 | 12.00 | 111 |
| 31 | 4 | graph | 4 | 2024-04-07 | 16.00 | uce2022447 |
| 32 | 1 | plain sheets | 1 | 2024-04-08 | 3.00 | u |
| 33 | 1 | plain sheets | 1 | 2024-04-08 | 3.00 | uce2022453 |
| 34 | 1 | plain sheets | 3 | 2024-04-08 | 9.00 | a
|
| 35 | 1 | plain sheets | 1 | 2024-04-08 | 3.00 | uce2022448 |
| 37 | 2 | Ruled Sheets | 5 | 2024-04-08 | 50.00 | uce2022453 |
| 38 | 1 | plain sheets | 4 | 2024-04-08 | 12.00 | abs |
| 39 | 3 | index page | 3 | 2024-04-13 | 9.00 | uce2022447 |
| 41 | 7 | SY comp file | 4 | 2024-04-13 | 4.00 | uce2022447 |
| 42 | 4 | graph | 5 | 2024-04-13 | 25.00 | uce2022447 |
| 43 | 4 | graph | 5 | 2024-04-13 | 25.00 | uce2022447 |
| 44 | 4 | graph | 5 | 2024-04-13 | 25.00 | uce2022454 |
| 46 | 4 | graph | 4 | 2024-04-14 | 20.00 | uce2022447 |
+------+------+---------------+----------+------------+-------------+-------------+
30 rows in set (0.00 sec)
2.Select * from Admin where Username = '"+username+"' and Password = '"+password
SELECT * FROM admin WHERE Username = 'Divya Pardeshi' AND Password = 'Div123';
+----------+------------------+----------+
| Admin_id | Username | Password |
+----------+------------------+----------+
| 101 | Divya Pardeshi | Div123 |
+----------+------------------+----------+
3."Select t_id from transaction order by t_id DESC LIMIT 1
+------+
| t_id |
+------+
| 46 |
+------+
4.Select roll_number from transaction order by t_id DESC LIMIT 1
+-------------+
| roll_number |
+-------------+
| uce2022447 |
+-------------+
5.Select Student_name from customer where roll_number = '"+rno+"'
SELECT Student_name FROM customer WHERE roll_number = '2';
+---------------+
| Student_name |
+---------------+
| Harry |
+---------------+
6.Select P_name from transaction order by t_id DESC LIMIT 1
+---------------+
| P_name |
+---------------+
| graph |
+---------------+
7.Select quantity from transaction order by t_id DESC LIMIT 1
+----------+
| quantity |
+----------+
| 4 |
+----------+
8.Select Total_price from transaction order by t_id DESC LIMIT 1
+-------------+
| Total_Price |
+-------------+
| 20.00 |
+-------------+
9.select roll_number from log order by sr_no desc limit 1";
+-------------+
| roll_number |
+-------------+
| uce2022447 |
+-------------+
10.Select quantity from transaction where roll_number= uce2022447 order by t_id DESC limit 1"
+----------+
| quantity |
+----------+
| 4 |
+----------+
11.Select p_Id from transaction where roll_number= '"uce2022457"'order by t_id DESC limit 1
+------+
| p_Id |
+------+
| 2 |
+------+
12.DELETE FROM transaction WHERE roll_number = 'uce2022457' ORDER BY t_id DESC LIMIT 1;
Query OK, 1 row affected
13.Select * from customer where roll_number='"+tt1+"'and phno='"+tt2+"'"
SELECT * FROM customer WHERE roll_number = 'uce2022458' AND phno = '1234567890';
+-------------+------------+------------+----------------+
| roll_number | Student_name | phno | department |
+-------------+------------+------------+----------------+
| uce2022458 | John Doe | 1234567890 | Computer Science |
+-------------+------------+------------+----------------+
14.SELECT Quantity FROM Product WHERE P_Id = 3;
+----------+
| Quantity |
+----------+
| 100 |
+----------+
15.SELECT Price FROM Product WHERE P_Id = 3;
+-------+
| Price |
+-------+
| 2 |
+-------+
16.select roll_number from log order by sr_no desc limit 1
+-------------+
| roll_number |
+-------------+
| uce2022447 |
+-------------+
17.INSERT INTO Product (P_Id, P_Name, Price, Category, Quantity, Admin_id)
VALUES (11, 'easer', 1, 'stationery', 100, 103);
+------+--------------------------+-------+------------+----------+----------+
| P_Id | P_Name | Price | Category | Quantity | Admin_id |
+------+--------------------------+-------+------------+----------+----------+
| 1 | Plain sheet | 1 | stationery | 100 | 101 |
| 2 | One sided Ruled sheet | 2 | stationery | 100 | 102 |
| 3 | Double sided Ruled sheet | 2 | stationery | 100 | 102 |
| 4 | Index sheet | 2 | stationery | 100 | 102 |
| 5 | Graph paper | 3 | stationery | 100 | 103 |
| 6 | Logarithmic Graph paper | 3 | stationery | 100 | 103 |
| 7 | FY file | 1 | stationery | 100 | 103 |
| 8 | SY file | 1 | stationery | 100 | 103 |
| 9 | TY file | 1 | stationery | 100 | 103 |
| 10 | BTech file | 1 | stationery | 100 | 103 |
| 11 | easer | 1 | stationery | 100 | 103 |
+------+--------------------------+-------+------------+----------+----------+
18.DELETE FROM Product WHERE P_Id = '11';
+------+--------------------------+-------+------------+----------+----------+
| P_Id | P_Name | Price | Category | Quantity | Admin_id |
+------+--------------------------+-------+------------+----------+----------+
| 1 | Plain sheet | 1 | stationery | 100 | 101 |
| 2 | One sided Ruled sheet | 2 | stationery | 100 | 102 |
| 3 | Double sided Ruled sheet | 2 | stationery | 100 | 102 |
| 4 | Index sheet | 2 | stationery | 100 | 102 |
| 5 | Graph paper | 3 | stationery | 100 | 103 |
| 6 | Logarithmic Graph paper | 3 | stationery | 100 | 103 |
| 7 | FY file | 1 | stationery | 100 | 103 |
| 8 | SY file | 1 | stationery | 100 | 103 |
| 9 | TY file | 1 | stationery | 100 | 103 |
| 10 | BTech file | 1 | stationery | 100 | 103 |
+------+--------------------------+-------+------------+----------+----------+
19.SELECT department, COUNT(*) AS total_students
FROM customer
GROUP BY department
ORDER BY total_students DESC;
+------------+----------------+
| department | total_students |
+------------+----------------+
| computer | 11 |
| NULL | 2 |
+------------+----------------+
20.SELECT Category, SUM(Quantity) AS total_quantity
FROM product
GROUP BY Category
ORDER BY total_quantity DESC;
+------------+----------------+
| Category | total_quantity |
+------------+----------------+
| stationery | 1100 |
+------------+----------------+
21.SELECT c.roll_number, c.Student_name, t.t_id
FROM customer c
LEFT OUTER JOIN transaction t ON c.roll_number = t.roll_number;
+-------------+---------------+------+
| roll_number | Student_name | t_id |
+-------------+---------------+------+
| 1 | Rose | NULL |
| 2 | Harry | NULL |
| 3 | Divya | NULL |
| uce2022447 | Khyati shetty | 1 |
| uce2022447 | Khyati shetty | 2 |
| uce2022448 | k | NULL |
| uce2022451 | Shrutika | NULL |
| uce2022454 | bhakti | NULL |
| uce2022455 | divya p | NULL |
| uce2022456 | divya | 11 |
| uce2022457 | ketaki dixit | NULL |
+-------------+---------------+------+
22.All transactions from Khyati
SELECT *
FROM transaction
WHERE roll_number IN (SELECT roll_number FROM customer WHERE Student_name = 'Khyati Shetty');
| t_id | P_Id | P_name | quantity | time_date | Total_Price | roll_number |
|------|------|--------------|----------|------------|-------------|-------------|
| 31 | 4 | graph | 4 | 2024-04-07 | 16.00 | uce2022447 |
| 39 | 3 | index page | 3 | 2024-04-13 | 9.00 | uce2022447 |
| 41 | 7 | SY comp file | 4 | 2024-04-13 | 4.00 | uce2022447 |
| 42 | 4 | graph | 5 | 2024-04-13 | 25.00 | uce2022447 |
| 43 | 4 | graph | 5 | 2024-04-13 | 25.00 | uce2022447 |
| 44 | 4 | graph | 5 | 2024-04-13 | 25.00 | uce2022454 |
| 46 | 4 | graph | 4 | 2024-04-14 | 20.00 | uce2022447 |
23.SELECT *
FROM transaction
WHERE time_date BETWEEN '2024-04-02' AND '2024-04-10';
+------+------+---------------+----------+------------+-------------+-------------+
| t_id | P_Id | P_name | quantity | time_date | Total_Price | roll_number |
+------+------+---------------+----------+------------+-------------+-------------+
| 1 | 1 | Index Sheets | 2 | 2024-04-02 | 10.00 | NULL |
| 2 | 2 | Ruled Sheets | 3 | 2024-04-02 | 30.00 | NULL |
| 3 | 3 | Plain Sheets | 5 | 2024-04-02 | 25.00 | NULL |
| 4 | 1 | Index Sheets | 1 | 2024-04-02 | 5.00 | NULL |
| 5 | 1 | Index Sheets | 12 | 2024-04-04 | 60.00 | NULL |
| 6 | 1 | Index Sheets | 12 | 2024-04-04 | 60.00 | NULL |
| 7 | 1 | Index Sheets | 12 | 2024-04-04 | 60.00 | NULL |
| 8 | 1 | Index Sheets | 12 | 2024-04-04 | 60.00 | NULL |
| 9 | 1 | Index Sheets | 12 | 2024-04-04 | 60.00 | NULL |
| 11 | 1 | Index Sheets | 23 | 2024-04-05 | 69.00 | uce2022456 |
| 12 | 1 | Index Sheets | 23 | 2024-04-05 | 69.00 | uce2022456 |
| 13 | 1 | Index Sheets | 23 | 2024-04-05 | 69.00 | uce2022456 |
| 14 | 1 | Index Sheets | 23 | 2024-04-05 | 69.00 | 1 |
| 16 | 1 | Index Sheets | 15 | 2024-04-05 | 45.00 | uce2022455 |
| 23 | 2 | Ruled Sheets | 2 | 2024-04-07 | 20.00 | 111 |
| 24 | 1 | plain sheets | 4 | 2024-04-07 | 12.00 | 111 |
| 25 | 1 | plain sheets | 4 | 2024-04-07 | 12.00 | 111 |
| 31 | 4 | graph | 4 | 2024-04-07 | 16.00 | uce2022447 |
| 32 | 1 | plain sheets | 1 | 2024-04-08 | 3.00 | u |
| 33 | 1 | plain sheets | 1 | 2024-04-08 | 3.00 | uce2022453 |
| 34 | 1 | plain sheets | 3 | 2024-04-08 | 9.00 | a
|
| 35 | 1 | plain sheets | 1 | 2024-04-08 | 3.00 | uce2022448 |
| 37 | 2 | Ruled Sheets | 5 | 2024-04-08 | 50.00 | uce2022453 |
| 38 | 1 | plain sheets | 4 | 2024-04-08 | 12.00 | abs |