dblabs/p.sql
2024-01-25 21:55:48 +01:00

12 lines
No EOL
433 B
SQL

--Same question as in question o) but with names instead of person numbers.
DROP VIEW IF EXISTS StudentsCredits;
CREATE VIEW StudentsCredits AS
SELECT Students.firstName, Students.lastName, sum(credits) as totalCredits
FROM Students
JOIN TakenCourses ON Students.pNbr = TakenCourses.pNbr
JOIN Courses ON TakenCourses.courseCode = Courses.courseCode
GROUP BY Students.pNbr;
SELECT * FROM StudentsCredits ORDER BY totalCredits DESC;