diff --git a/makefile b/makefile index de75ba9..2a0bd51 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,5 @@ DB_NAME := lab.db -SQL_FILES := init.sql lab1.sql a.sql b.sql c.sql d.sql e.sql f.sql g.sql h.sql i.sql j.sql k.sql l.sql m.sql n.sql o.sql +SQL_FILES := init.sql lab1.sql a.sql b.sql c.sql d.sql e.sql f.sql g.sql h.sql i.sql j.sql k.sql l.sql m.sql n.sql o.sql p.sql q.sql .PHONY: all clean diff --git a/p.sql b/p.sql new file mode 100644 index 0000000..eb58a4a --- /dev/null +++ b/p.sql @@ -0,0 +1,10 @@ +DROP VIEW IF EXISTS StudentsCredits; + +CREATE VIEW StudentsCredits AS +SELECT Students.firstName, 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; \ No newline at end of file diff --git a/q.sql b/q.sql new file mode 100644 index 0000000..960e784 --- /dev/null +++ b/q.sql @@ -0,0 +1,4 @@ +SELECT firstName, lastName, count(*) as nbrOfStudents +FROM Students +GROUP BY firstName, lastName +HAVING count(*) > 1; \ No newline at end of file