Added comments and small changes

This commit is contained in:
dDogge 2024-01-25 21:55:48 +01:00
parent 3fef57df8a
commit e7c140a319
17 changed files with 41 additions and 4 deletions

2
a.sql
View file

@ -1,4 +1,4 @@
-- What are the names (first name, last name) of all the students?
--What are the names (first name, last name) of all the students? [72]
select firstName, lastName
from Students

2
b.sql
View file

@ -1,3 +1,5 @@
--Same as in a) but produce a sorted listing. Sort first by last name and then by first name.
select firstName, lastName
from Students
order by lastName, firstName

2
c.sql
View file

@ -1,3 +1,5 @@
--Which students were born in 1975?
select firstName, lastName
from Students
where pNbr like '1975%'

3
d.sql
View file

@ -1,3 +1,6 @@
--What are the names of the female students, and which are their person numbers?
--The next-to-last digit in the person number is even for females[26]
select firstName, pNbr
from Students
where substring(pNbr, LENGTH(pNbr) -1, 1) % 2 = 0

4
e.sql
View file

@ -1,2 +1,4 @@
select distinct pNbr
--How many students are registered in the database?
select count(*)
from Students

3
f.sql
View file

@ -1,3 +1,6 @@
--Which courses are offered by the department of Mathematics
--(course codes FMAxxx)? [24]
select courseName
from Courses
where courseCode like '%FMA%'

2
g.sql
View file

@ -1,3 +1,5 @@
--Which courses give more than five credits? [21]
select courseName
from Courses
where credits > 5

3
h.sql
View file

@ -1,3 +1,6 @@
--Which courses (course codes only) have been taken by the student with person
--num-ber 790101-1234? [7]
select courseCode
from TakenCourses
where pNbr = '790101-1234'

2
i.sql
View file

@ -1,3 +1,5 @@
--What are the names of these courses, and how many credits do they give?
select courseName, credits, courseCode, pNbr
from Courses
join Students on Students.pNbr

2
j.sql
View file

@ -1,3 +1,5 @@
--How many credits has the student taken?
select sum(credits) as totalSum
from Courses
join Students on Students.pNbr

2
k.sql
View file

@ -1,3 +1,5 @@
--Which is the students grade average on the courses that he has taken?
select avg(TakenCourses.grade) as averageGrade, Students.pNbr
from TakenCourses
join Students on TakenCourses.pNbr = Students.pNbr

2
l.sql
View file

@ -1,3 +1,5 @@
--Same questions as in questions h)-k), but for the student Eva Alm. [5]
select firstName, lastName, avg(TakenCourses.grade) as averageGrade, TakenCourses.courseCode, Courses.courseName, sum(Courses.credits) as totalCredits
from TakenCourses
join Students on TakenCourses.pNbr = Students.pNbr

4
m.sql
View file

@ -1,4 +1,6 @@
select distinct firstName
--Which students have taken 0 credits? [16]
select firstName, lastName
from Students
left join TakenCourses on Students.pNbr = TakenCourses.pNbr
where TakenCourses.pNbr is null

3
n.sql
View file

@ -1,3 +1,6 @@
--Which student has the highest grade average? Advice: define and use a view that
--gives the person number and grade average for each student.
DROP VIEW IF EXISTS StudentsAverages;
CREATE VIEW StudentsAverages AS

3
o.sql
View file

@ -1,3 +1,6 @@
--List the person number and total number of credits for all students.
--Students with no credits should be included in the list! [72]
DROP VIEW IF EXISTS StudentsCredits;
CREATE VIEW StudentsCredits AS

4
p.sql
View file

@ -1,7 +1,9 @@
--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, sum(credits) as totalCredits
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

2
q.sql
View file

@ -1,3 +1,5 @@
--Is there more than one student with the same name? If so, who are these students? [7]
SELECT firstName, lastName, count(*) as nbrOfStudents
FROM Students
GROUP BY firstName, lastName