2024-01-25 21:55:48 +01:00
|
|
|
--Which student has the highest grade average? Advice: define and use a view that
|
|
|
|
--gives the person number and grade average for each student.
|
|
|
|
|
2024-01-25 20:33:02 +01:00
|
|
|
DROP VIEW IF EXISTS StudentsAverages;
|
|
|
|
|
|
|
|
CREATE VIEW StudentsAverages AS
|
|
|
|
SELECT Students.firstName, Students.pNbr, TakenCourses.grade, avg(grade) as averageGrade
|
|
|
|
FROM Students
|
|
|
|
JOIN TakenCourses ON Students.pNbr = TakenCourses.pNbr
|
|
|
|
GROUP BY Students.pNbr;
|
|
|
|
|
2024-01-26 17:05:32 +01:00
|
|
|
SELECT firstName, averageGrade FROM StudentsAverages
|
|
|
|
WHERE averageGrade = max(averageGrade);
|