dblabs/o.sql

13 lines
480 B
MySQL
Raw Permalink Normal View History

2024-01-25 21:55:48 +01:00
--List the person number and total number of credits for all students.
--Students with no credits should be included in the list! [72]
2024-01-25 21:05:45 +01:00
DROP VIEW IF EXISTS StudentsCredits;
CREATE VIEW StudentsCredits AS
SELECT Students.pNbr, 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;