-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql.html
More file actions
396 lines (371 loc) · 11.2 KB
/
mysql.html
File metadata and controls
396 lines (371 loc) · 11.2 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MySQL Questions - CS Practical</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<main>
<a href="index.html" class="back-link">← Back to Home</a>
<h1>MySQL</h1>
<div class="subtitle">CS10 Laboratory</div>
<div id="toc" class="toc">
<h2>Contents</h2>
<ul>
<li><a href="#tables">1 Data Tables</a></li>
<li><a href="#queries">2 Questions and Queries</a></li>
</ul>
</div>
<h3 id="tables">Data Tables</h3>
<h4>Table: STUDENT</h4>
<table>
<thead>
<tr>
<th>Roll no.</th>
<th>Name</th>
<th>Class</th>
<th>Marks</th>
<th>City</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Amit Sharma</td>
<td>XII</td>
<td>85</td>
<td>Delhi</td>
</tr>
<tr>
<td>2</td>
<td>Neha Verma</td>
<td>XI</td>
<td>78</td>
<td>Mumbai</td>
</tr>
<tr>
<td>3</td>
<td>Rohit Kumar</td>
<td>XII</td>
<td>92</td>
<td>Delhi</td>
</tr>
<tr>
<td>4</td>
<td>Sneha Singh</td>
<td>XI</td>
<td>88</td>
<td>Kolkata</td>
</tr>
<tr>
<td>5</td>
<td>Arjun Mehta</td>
<td>XII</td>
<td>74</td>
<td>Chennai</td>
</tr>
</tbody>
</table>
<h4>Table: SPORTS</h4>
<table>
<thead>
<tr>
<th>Sports ID</th>
<th>Roll no.</th>
<th>Sports Name</th>
<th>Level</th>
</tr>
</thead>
<tbody>
<tr>
<td>101</td>
<td>1</td>
<td>Football</td>
<td>School</td>
</tr>
<tr>
<td>102</td>
<td>2</td>
<td>Cricket</td>
<td>State</td>
</tr>
<tr>
<td>103</td>
<td>3</td>
<td>Badminton</td>
<td>National</td>
</tr>
<tr>
<td>104</td>
<td>4</td>
<td>Athletics</td>
<td>School</td>
</tr>
<tr>
<td>105</td>
<td>5</td>
<td>Basketball</td>
<td>State</td>
</tr>
<tr>
<td>106</td>
<td>6</td>
<td>Athletics</td>
<td>School</td>
</tr>
<tr>
<td>107</td>
<td>7</td>
<td>Hockey</td>
<td>National</td>
</tr>
</tbody>
</table>
<h3 id="queries">Questions and Queries</h3>
<h4>Q.1) Display name of all students.</h4>
<code>SELECT Name FROM STUDENT;</code>
<table>
<tr>
<th>Name</th>
</tr>
<tr>
<td>Amit Sharma</td>
</tr>
<tr>
<td>Neha Verma</td>
</tr>
<tr>
<td>Rohit Kumar</td>
</tr>
<tr>
<td>Sneha Singh</td>
</tr>
<tr>
<td>Arjun Mehta</td>
</tr>
</table>
<h4>Q.2) Show the name of students who scored more than 80 marks.</h4>
<code>SELECT Name FROM STUDENT WHERE Marks > 80;</code>
<table>
<tr>
<th>Name</th>
</tr>
<tr>
<td>Amit Sharma</td>
</tr>
<tr>
<td>Rohit Kumar</td>
</tr>
<tr>
<td>Sneha Singh</td>
</tr>
</table>
<h4>Q.3) List the name of students belonging to Class 12.</h4>
<code>SELECT Name FROM STUDENT WHERE Class = 'XII';</code>
<table>
<tr>
<th>Name</th>
</tr>
<tr>
<td>Amit Sharma</td>
</tr>
<tr>
<td>Rohit Kumar</td>
</tr>
<tr>
<td>Arjun Mehta</td>
</tr>
</table>
<h4>Q.4) Display the name and marks of students in descending order of marks.</h4>
<code>SELECT Name, Marks FROM STUDENT ORDER BY Marks DESC;</code>
<table>
<tr>
<th>Name</th>
<th>Marks</th>
</tr>
<tr>
<td>Rohit Kumar</td>
<td>92</td>
</tr>
<tr>
<td>Sneha Singh</td>
<td>88</td>
</tr>
<tr>
<td>Amit Sharma</td>
<td>85</td>
</tr>
<tr>
<td>Neha Verma</td>
<td>78</td>
</tr>
<tr>
<td>Arjun Mehta</td>
<td>74</td>
</tr>
</table>
<h4>Q.5) Count the no. of students from each city.</h4>
<code>SELECT City, COUNT(*) AS "Total Students" FROM STUDENT GROUP BY City;</code>
<table>
<tr>
<th>City</th>
<th>Total Students</th>
</tr>
<tr>
<td>Delhi</td>
<td>2</td>
</tr>
<tr>
<td>Mumbai</td>
<td>1</td>
</tr>
<tr>
<td>Kolkata</td>
<td>1</td>
</tr>
<tr>
<td>Chennai</td>
<td>1</td>
</tr>
</table>
<h4>Q.6) Display the highest marks obtained by any student.</h4>
<code>SELECT MAX(Marks) AS "Highest Marks" FROM STUDENT;</code>
<table>
<tr>
<th>Highest Marks</th>
</tr>
<tr>
<td>92</td>
</tr>
</table>
<h4>Q.7) Show the name of student who participated in sports (using join).</h4>
<button class="action-btn" onclick="toggleQ7Solution()">🔄 Switch Solution</button>
<!-- Solution 1: With Student Name and Sports Name (Primary) -->
<div id="q7-solution1">
<p><b>📚 Solution by Sir:</b></p>
<code>SELECT STUDENT.Name AS "STUDENT NAME", SPORTS.Sports_Name AS "SPORTS NAME" FROM STUDENT, SPORTS WHERE STUDENT.Roll_no = SPORTS.Roll_no;</code>
<table>
<tr>
<th>STUDENT NAME</th>
<th>SPORTS NAME</th>
</tr>
<tr>
<td>Amit Sharma</td>
<td>Football</td>
</tr>
<tr>
<td>Amit Sharma</td>
<td>Athletics</td>
</tr>
<tr>
<td>Neha Verma</td>
<td>Athletics</td>
</tr>
<tr>
<td>Rohit Kumar</td>
<td>Cricket</td>
</tr>
<tr>
<td>Rohit Kumar</td>
<td>Hockey</td>
</tr>
<tr>
<td>Sneha Singh</td>
<td>Badminton</td>
</tr>
<tr>
<td>Arjun Mishra</td>
<td>Basketball</td>
</tr>
</table>
</div>
<!-- Solution 2: Simple Name query (Alternative) -->
<div id="q7-solution2" style="display: none;">
<p><b>🤖 Solution by ChatGPT:</b></p>
<p><b>Without JOIN keyword:</b></p>
<code>SELECT Name FROM STUDENT, SPORTS WHERE STUDENT.Roll_no = SPORTS.Roll_no;</code>
<p><b>Using INNER JOIN:</b></p>
<code>SELECT STUDENT.Name FROM STUDENT INNER JOIN SPORTS ON STUDENT.Roll_no = SPORTS.Roll_no;</code>
<table>
<tr>
<th>Name</th>
</tr>
<tr>
<td>Amit Sharma</td>
</tr>
<tr>
<td>Neha Verma</td>
</tr>
<tr>
<td>Rohit Kumar</td>
</tr>
<tr>
<td>Sneha Singh</td>
</tr>
<tr>
<td>Arjun Mehta</td>
</tr>
</table>
</div>
<h4>Q.8) Display the name of students who play at the national level.</h4>
<code>SELECT Name FROM STUDENT, SPORTS WHERE STUDENT.Roll_no = SPORTS.Roll_no AND Level = 'National';</code>
<table>
<tr>
<th>Name</th>
</tr>
<tr>
<td>Rohit Kumar</td>
</tr>
</table>
<h4>Q.9) Display all the unique cities of students.</h4>
<code>SELECT DISTINCT City FROM STUDENT;</code>
<table>
<tr>
<th>City</th>
</tr>
<tr>
<td>Delhi</td>
</tr>
<tr>
<td>Mumbai</td>
</tr>
<tr>
<td>Kolkata</td>
</tr>
<tr>
<td>Chennai</td>
</tr>
</table>
<h4>Q.10) Find the total marks obtained by all the students.</h4>
<code>SELECT SUM(Marks) AS "Total Marks" FROM STUDENT;</code>
<table>
<tr>
<th>Total Marks</th>
</tr>
<tr>
<td>417</td>
</tr>
</table>
</main>
<footer>
<p>CS Practical Questions</p>
</footer>
<script src="script.js"></script>
<script>
// Toggle Q7 between Solution 1 (Name + Sports) and Solution 2 (Name only with JOIN variants)
function toggleQ7Solution() {
const sol1 = document.getElementById('q7-solution1');
const sol2 = document.getElementById('q7-solution2');
if (sol1.style.display === 'none') {
sol1.style.display = 'block';
sol2.style.display = 'none';
} else {
sol1.style.display = 'none';
sol2.style.display = 'block';
}
}
</script>
</body>
</html>