-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase managementstudent
More file actions
729 lines (602 loc) · 16.7 KB
/
Database managementstudent
File metadata and controls
729 lines (602 loc) · 16.7 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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
#Creat Newdatabase
CREATE DATABASE StudentInformationSystem;
USE StudentInformationSystem;
# Remove Databases
DROP DATABASE IF EXISTS StudentInformationSystem;
#Creat Table and Link with Foreign key
CREATE TABLE StudentInformationSystem.Department(
IdDepartment INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
Sign TEXT,
Contact TEXT
) ENGINE=INNODB;
CREATE TABLE StudentInformationSystem.InformationStudent(
FirstName VARCHAR(60) NOT NULL,
LastName VARCHAR(30) NOT NULL,
IdStudent INT UNIQUE AUTO_INCREMENT,
DateOfBirth DATE,
Sex VARCHAR(10),
Phone TEXT,
IdDepartment INT,
FinalScore FLOAT,
PRIMARY KEY (IdStudent,FinalScore),
CONSTRAINT Manage_Student
FOREIGN KEY (IdDepartment)
REFERENCES StudentInformationSystem.Department(IdDepartment)
ON UPDATE RESTRICT
ON DELETE CASCADE
)ENGINE=INNODB;
CREATE TABLE StudentInformationSystem.Learn(
IdStudent INT,
Math FLOAT,
Graphics FLOAT,
Electric FLOAT,
Mechanical FLOAT,
English FLOAT,
Exercise FLOAT,
Phisical FLOAT,
Astronomy FLOAT,
CONSTRAINT Study
FOREIGN KEY (IdStudent)
REFERENCES StudentInformationSystem.InformationStudent(IdStudent)
ON UPDATE RESTRICT
ON DELETE CASCADE
)ENGINE=INNODB;
#/////////////////////////////Start Test////////////////////////////////
# Test Trigger
CREATE TABLE StudentInformationSystem.Reference(
FirstName VARCHAR(60) NOT NULL,
LastName VARCHAR(30) NOT NULL,
IdStudent INT,
FinalScore FLOAT,
NewFinalScore FLOAT,
CHECK (FinalScore >=0 AND FinalScore<=10)
/* PRIMARY KEY (IdStudent,FinalScore),
CONSTRAINT Manage_Student
FOREIGN KEY (IdDepartment)
REFERENCES StudentInformationSystem.Department(IdDepartment)
ON UPDATE RESTRICT
ON DELETE CASCADE*/
)ENGINE=INNODB;
# End test Trigger
#Test Foreign Key
CREATE TABLE StudentInformationSystem.Learn(
IdStudent INT,
IdUses INT,
FinalScoreUpdate INT,
PRIMARY KEY (IdStudent,FinalScoreUpdate),
CONSTRAINT Study
FOREIGN KEY (IdStudent)
REFERENCES StudentInformationSystem.InformationStudent(IdStudent)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY (IdUses)
REFERENCES StudentInformationSystem.Department(IdDepartment)
ON UPDATE CASCADE
ON DELETE CASCADE
# FOREIGN KEY (FinalScoreUpdate)
# REFERENCES StudentInformationSystem.InformationStudent(FinalScore)
# ON UPDATE CASCADE
#ON DELETE CASCADE
)ENGINE=INNODB;
USE StudentInformationSystem;
DELIMITER $$
CREATE TRIGGER after_InformationStudent_update
AFTER UPDATE ON StudentInformationSystem.InformationStudent
FOR EACH ROW
BEGIN
IF OLD.FinalScore <> new.FinalScore THEN
INSERT INTO StudentInformationSystem.Reference(FirstName,LastName,IdStudent,NewFinalScore)
VALUES(OLD.FirstName, OLD.LastName,OLD.IdStudent,NEW.FinalScore);
END IF;
END $$
DELIMITER ;
####//////////////End Test///////////////////////////
INSERT INTO StudentInformationSystem.InformationStudent(FirstName,LastName,DateOfBirth,Sex,Phone,IdDepartment,FinalScore)
VALUES('Tran Van','Lam','1991-07-27','Female','0968657666',1002,8),
('Tran Nhat','Quang','1991-11-06','Male','0945276868',1002,9);
INSERT INTO StudentInformationSystem.Learn(Idstudent,IdUses)
VALUES(556,1002)
DELETE FROM StudentInformationSystem.Learn
WHERE IdStudent=200;
UPDATE StudentInformationSystem.InformationStudent
SET
IdStudent =555
WHERE
IdStudent=1000;
# End Test
# Insert Detail
INSERT INTO StudentInformationSystem.Department(Name,Sign,Contact)
VALUES('Mechanical','ME','0246457845');
INSERT INTO StudentInformationSystem.InformationStudent(FirstName,LastName,IdUseSystem,DateOfBirth,Sex,Phone,IdDepartment,FinalScore)
VALUES#('Ngo Kim','Thoa',200,500,'1991-07-27','Female','0968657666',1000)
#('Tran Nhat','Quang',600,2015,'1991-11-06','Male','0945276868',1001,8.5),
('Tran Van','Phong',2016,'1991-10-04','Male','0983682552',1001,9.5);
#('Do Nhu','Trang',700,'1991-08-25','Female','0945795665',1002);
#('Nguyen Thi Kim ','Hue','1991-05-10','Female','091236555',1003);
INSERT INTO StudentInformationSystem.Learn(IdStudent,Math,Graphics,Electric,Mechanical,English,Exercise,Phisical,Astronomy)
VALUES(20160,4.5,3.5,5,4,3.5,5,4.5,6),
(20170,4,6.5,4,3.5,6,4.5,4,5.5),
(20171,5,5.5,4,3.5,6,4.5,6,5.5),
(20172,8,7.5,6,8.5,6,5,6,8),
(20173,6.5,5.5,4,9.5,8.5,8.5,5.5,9),
(20174,9,7.5,8.5,8,7.5,8,8,10),
(20175,8,9.5,9.5,8,8.5,8.5,8.5,9),
(20176,9,8.5,9.5,8,9,9,7.5,8),
(20177,9,8,9.5,9,9,8,10,9.5),
(20178,8,8.5,9.5,8.5,8.5,8,9,9),
(20179,9.5,10,9.5,8,8,8,10,8.5),
(20180,9,9,9,9,9,9,10,9.5),
(20181,8.5,8.5,6.5,6,8.5,8,8.5,8.5),
(20182,9,5.5,9.5,8,875,8,9.5,9.5);
#Update value on table to change value on table
UPDATE StudentInformationSystem.Department
SET
IdDepartment=555
WHERE
IdDepartment = 1000;
# Delete dât on table
DELETE FROM StudentInformationSystem.Department
WHERE IdDepartment=1000;
# Calcule AVG of all student
SELECT
IdStudent,
AVG((Math+Graphics+Electric+Mechanical+English+Exercise+Phisical+Astronomy)/8) 'Avegrage'
FROM
ManagementStudent.Learn
GROUP BY
IdStudent;
# Creat Group By to Sum and Arverage
SELECT
IdStudent,
SUM(Math+Graphics+Electric+Mechanical+English+Exercise+Phisical+Astronomy) AS total,
COUNT(*)AS number123,
SUM((Math+Graphics+Electric+Mechanical+English+Exercise+Phisical+Astronomy)/8) AS Average
FROM
ManagementStudent.Learn
GROUP BY
IdStudent;
# Creat Group By to Sum and Arverage And Iner
SELECT
IdStudent,
FirstName,
LastName,
SUM(Math+Graphics+Electric+Mechanical+English+Exercise+Phisical+Astronomy) AS total,
SUM((Math+Graphics+Electric+Mechanical+English+Exercise+Phisical+Astronomy)/8) AS Average,
COUNT(*)AS number123
FROM
ManagementStudent.Infomation
INNER JOIN ManagementStudent.Learn
USING (IdStudent)
GROUP BY
IdStudent;
# Filter Top 3 hightest Using Limit and Join
SELECT
IdStudent,
FirstName,
LastName,
IdDepartment,
SUM(Math+Graphics+Electric+Mechanical+English+Exercise+Phisical+Astronomy) AS total,
SUM((Math+Graphics+Electric+Mechanical+English+Exercise+Phisical+Astronomy)/8) AS Average,
COUNT(*)AS number123
FROM
ManagementStudent.Infomation
JOIN ManagementStudent.Learn
USING (IdStudent)
GROUP BY
IdStudent
ORDER BY
total DESC
LIMIT 0,3;
# Filter Top Student Total< 40 (Detail Average < 5) Using Limit and Iner
SELECT
IdStudent,
FirstName,
LastName,
IdDepartment,
Sign,
SUM(Math+Graphics+Electric+Mechanical+English+Exercise+Phisical+Astronomy) AS total,
SUM((Math+Graphics+Electric+Mechanical+English+Exercise+Phisical+Astronomy)/8) AS Average,
COUNT(*)AS number123
FROM
ManagementStudent.Infomation
JOIN ManagementStudent.Learn
USING (IdStudent)
JOIN ManagementStudent.Department
USING(IdDepartment)
GROUP BY
IdStudent,
IdDepartment
HAVING
Average<5
ORDER BY
total;
# Number student on Department
SELECT
IdDepartment,
Name,
Sign,
COUNT(*) AS TotalStudent
FROM
ManagementStudent.Infomation i
JOIN ManagementStudent.Department
USING (IdDepartment)
GROUP BY
IdDepartment;
# Number student are Female on Department
SELECT
IdDepartment,
Name,
Sign,
COUNT(*) AS Number_Female
FROM
ManagementStudent.Infomation i
JOIN ManagementStudent.Department
USING (IdDepartment)
WHERE
Sex='Female'
GROUP BY
IdDepartment;
# List Top 3 Student have Hightest score in IT
SELECT
IdStudent,
FirstName,
LastName,
IdDepartment,
Sign,
SUM(Math+Graphics+Electric+Mechanical+English+Exercise+Phisical+Astronomy) AS total,
SUM((Math+Graphics+Electric+Mechanical+English+Exercise+Phisical+Astronomy)/8) AS Average,
COUNT(*)AS number123
FROM
ManagementStudent.Infomation
JOIN ManagementStudent.Learn
USING (IdStudent)
JOIN ManagementStudent.Department
USING(IdDepartment)
WHERE IdDepartment=1000
GROUP BY
IdStudent,
IdDepartment
ORDER BY
total DESC
LIMIT 0,3;
#list student have Average Score >8.0 in IT Department
SELECT
IdStudent,
FirstName,
LastName,
IdDepartment,
Sign,
SUM(Math+Graphics+Electric+Mechanical+English+Exercise+Phisical+Astronomy) AS total,
SUM((Math+Graphics+Electric+Mechanical+English+Exercise+Phisical+Astronomy)/8) AS Average,
COUNT(*)AS number123
FROM
ManagementStudent.Infomation
JOIN ManagementStudent.Learn
USING (IdStudent)
JOIN ManagementStudent.Department
USING(IdDepartment)
WHERE IdDepartment=1000
GROUP BY
IdStudent,
IdDepartment
HAVING
Average>8
ORDER BY
total DESC;
# list student have score is 10 of Graphics
SELECT
IdStudent,
FirstName,
LastName,
IdDepartment,
Graphics
FROM
ManagementStudent.Infomation
JOIN ManagementStudent.Learn
USING (IdStudent)
WHERE Graphics =10;
ORDER BY
IdStudent DESC;
# Stored Produce
DELIMITER $$
CREATE PROCEDURE GoodGraphic()
BEGIN
SELECT
IdStudent,
FirstName,
LastName,
IdDepartment,
Graphics
FROM
ManagementStudent.Infomation
JOIN ManagementStudent.Learn
USING (IdStudent)
WHERE Graphics =10;
ORDER BY
IdStudent DESC;
END$$
DELIMITER ;
#
#/////////////////////////////////////////////////////////////////////////////////////#
#///////////////////////////Build ManagementStudent DataBases/////////////////////////#
#Creat Newdatabase
CREATE DATABASE ManagementStudent;
USE ManagementStudent;
# Creat Mutitable
CREATE TABLE ManagementStudent.Department(
IdDepartment INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
Sign TEXT,
Contact TEXT
) ENGINE=INNODB ;
CREATE TABLE ManagementStudent.Lecture(
IdLecture INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
FirstNameLecture VARCHAR(100) NOT NULL,
LastNameLecture VARCHAR(50) NOT NULL,
Sex VARCHAR(50),
IdDepartment INT NOT NULL,
ContactLecture TEXT,
CONSTRAINT Manage_Lecture
FOREIGN KEY (IdDepartment)
REFERENCES ManagementStudent.Department(IdDepartment)
ON UPDATE CASCADE
ON DELETE CASCADE
) ENGINE=INNODB;
CREATE TABLE ManagementStudent.StudentInformation(
FirstName VARCHAR(60) NOT NULL,
LastName VARCHAR(30) NOT NULL,
IdStudent INT UNIQUE AUTO_INCREMENT,
Sex VARCHAR(10),
DateOfBirth DATE,
Phone TEXT,
IdDepartment INT,
PRIMARY KEY (IdStudent),
CONSTRAINT Manage_Student
FOREIGN KEY (IdDepartment)
REFERENCES ManagementStudent.Department(IdDepartment)
ON UPDATE CASCADE
ON DELETE CASCADE
)ENGINE=INNODB;
CREATE TABLE ManagementStudent.Subject(
IdSubject INT UNIQUE AUTO_INCREMENT,
NameSubject VARCHAR(60) NOT NULL,
SignSubject VARCHAR(60) NOT NULL,
Test1 FLOAT,
Test2 FLOAT,
FinalTest FLOAT,
PRIMARY KEY (IdSubject)
)ENGINE=INNODB;
CREATE TABLE ManagementStudent.Study(
IdStudent INT,
IdSubject INT,
Point1 FLOAT,
Point2 FLOAT,
FinalPoint FLOAT,
FOREIGN KEY (IdStudent)
REFERENCES ManagementStudent.StudentInformation(IdStudent)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY (IdSubject)
REFERENCES ManagementStudent.Subject(IdSubject)
ON UPDATE CASCADE
ON DELETE CASCADE
)ENGINE=INNODB;
CREATE TABLE ManagementStudent.Teach(
IdLecture INT,
IdSubject INT,
FOREIGN KEY (IdLecture)
REFERENCES ManagementStudent.Lecture(IdLecture)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY (IdSubject)
REFERENCES ManagementStudent.Subject(IdSubject)
ON UPDATE CASCADE
ON DELETE CASCADE
)ENGINE=INNODB;
#/////////// Insert Data on table////////////#
INSERT INTO ManagementStudent.Department(Name,Sign,Contact)
VALUES('Heat Engineering And Refrigretion','HER','0242257585');
INSERT INTO ManagementStudent.Lecture(FirstNameLecture,LastNameLecture,Sex,IdDepartment,ContactLecture)
VALUES('Trinh Dong','Tinh','Male',1005,'0242257585'),
('Vu Le','Quyen','Female',1002,'0242257585'),
('Tran Dinh','Canh','Male',1000,'0242257585'),
('Hoang Hong','Hai','Male',1004,'0242257585'),
('Mac Thi','Thoa','Male',1001,'0242257585'),
('Nguyen Pham','Hung','Male',1002,'0242257585'),
('Mai Thi','Lan','Female',1003,'0242257585'),
('Tran Thanh','Thao','Female',1005,'0242257585'),
('Nguyen Dinh','Thanh','Male',1002,'0242257585'),
('Vu Van','Cong','Male',1000,'0242257585');
INSERT INTO ManagementStudent.StudentInformation(FirstName,LastName,Sex,DateOfBirth,Phone,IdDepartment)
VALUES('Phan Hong','Long','Male','1991-07-27','0968657666',1000),
('Tran Nhat','Thanh','Male','1991-11-06','0945276868',1001),
('Tran Van','Canh','Male','1991-10-04','0983682552',1004),
('Do Nhu','Quyen','Female','1991-08-25','0945795665',1002),
('Nguyen Thi','Hoa','Female','1991-05-10','091236555',1003),
('Vu Nhat ','Long','Female','1991-05-12','091247555',1005);
INSERT INTO ManagementStudent.Subject(NameSubject,SignSubject,Test1,Test2,FinalTest)
VALUES('Medicine','M',0.2,0.3,0.5),
('Astronomy','AS',0.2,0.4,0.4),
('Accountancy','AC',0.3,0.3,0.4),
('Architecture','AR',0.2,0.3,0.5),
('Foreign language','AL',0.2,0.3,0.5),
('Chemistry','CHE',0.2,0.3,0.5),
('Economics ','EC',0.3,0.3,0.4),
('Politics','PO',0.2,0.4,0.4),
('Physics','PHY',0.1,0.4,0.5),
('Design and technology','DT',0.2,0.3,0.5),
('Law','LA',0.2,0.4,0.4),
('National Defense Education','NDE',0.3,0.3,0.4);
INSERT INTO ManagementStudent.Study(Idstudent,IdSubject,Point1,Point2,FinalPoint)
VALUES
(3013,4001,9,7,6),
(3013,4004,8,7,5),
(3013,4007,8,7,5),
(3013,4009,8,6,9),
(3013,4010,8,8.5,7),
#(3013,4012,8,6,7),
(3013,4013,9,8,9);
INSERT INTO ManagementStudent.Teach(IdLecture,IdSubject)
VALUES
(2011,4004),
(2011,4005),
(2011,4009);
UPDATE ManagementStudent.Study
SET
Point1 =9,
FinalPoint=9.5
WHERE
IdStudent=3012 AND IdSubject =4010;
# Query Filter Data
# Cacular Average point all Student For Seasion
SELECT
IdStudent,
FirstName,
LastName,
AVG(Point1*Test1+Point2*test2+FinalPoint*FinalTest) AS Average
FROM
ManagementStudent.Study
JOIN ManagementStudent.StudentInformation
USING (IdStudent)
JOIN ManagementStudent.Subject
USING (IdSubject)
GROUP BY
IdStudent;
# Student award for Avegrage >=7.5
SELECT
IdStudent,
FirstName,
LastName,
AVG(Point1*Test1+Point2*test2+FinalPoint*FinalTest) AS Average
FROM
ManagementStudent.Study
JOIN ManagementStudent.StudentInformation
USING (IdStudent)
JOIN ManagementStudent.Subject
USING (IdSubject)
GROUP BY
IdStudent
HAVING Average>=7.5
ORDER BY Average DESC;
# Top 3 Have Hightest Average Score
SELECT
IdStudent,
FirstName,
LastName,
AVG(Point1*Test1+Point2*test2+FinalPoint*FinalTest) AS Average
FROM
ManagementStudent.Study
JOIN ManagementStudent.StudentInformation
USING (IdStudent)
JOIN ManagementStudent.Subject
USING (IdSubject)
GROUP BY
IdStudent
ORDER BY Average DESC
LIMIT 3;
#Calcular Avegrage Every Subject of Every Student
SELECT
IdStudent,
FirstName,
LastName,
IdSubject,
NameSubject,
SUM(Point1*Test1+Point2*test2+FinalPoint*FinalTest) AS Average
FROM
ManagementStudent.Study
JOIN ManagementStudent.StudentInformation
USING (IdStudent)
JOIN ManagementStudent.Subject
USING (IdSubject)
WHERE IdStudent=3000
GROUP BY
IdSubject;
#creat View Table, Auto update value
CREATE VIEW ManagementStudent.Reference AS
SELECT
IdStudent,
FirstName,
LastName,
Name,
AVG(Point1*Test1+Point2*test2+FinalPoint*FinalTest) AS Average
FROM ManagementStudent.Study
JOIN ManagementStudent.StudentInformation
USING (IdStudent)
JOIN ManagementStudent.Subject
USING (IdSubject)
JOIN ManagementStudent.Department
USING (IdDepartment)
GROUP BY
IdStudent;
SELECT * FROM ManagementStudent.Reference;
# Test
UPDATE ManagementStudent.Study
SET
Point1 =9,
FinalPoint=9.5
WHERE
IdStudent=3012 AND IdSubject =4010;
#Calcular Avegrage Every Subject of Every Student
SELECT
IdStudent,
FirstName,
LastName,
IdSubject,
NameSubject,
SUM(DISTINCT Point1*Test1+Point2*test2+FinalPoint*FinalTest) AS Average
FROM
ManagementStudent.Study
JOIN ManagementStudent.StudentInformation
USING (IdStudent)
JOIN ManagementStudent.Subject
USING (IdSubject)
WHERE IdStudent=3000
GROUP BY
IdSubject;
#/////////////////Creat Ranking///////////////////#
WITH ManagementStudent.cte AS (
SELECT
IdStudent,
FirstName,
LastName,
AVG(Point1*Test1+Point2*test2+FinalPoint*FinalTest) AS Average
FROM
ManagementStudent.Study
JOIN ManagementStudent.StudentInformation
USING (IdStudent)
JOIN ManagementStudent.Subject
USING (IdSubject)
GROUP BY
IdStudent
)
SELECT
IdStudent,
FirstName,
LastName,
Average,
CASE Average
WHEN 8.2 THEN 'Very Good'
#WHEN THEN 'Repeated Customer'
#WHEN 3 THEN 'Frequent Customer'
ELSE 'Bad'
END Ranking
FROM
ManagementStudent.cte
ORDER BY Average;
#Test
WITH ManagementStudent.abc AS
(
SELECT
IdStudent,
FirstName,
LastName
FROM ManagementStudent.StudentInformation
)
SELECT*FROM ManagementStudent.abc;
# creat connect
dbconfig.php
$host = 'localhost';
$dbname = 'classicmodels';
$username = 'root';
$password = '';