Added comments and small changes
This commit is contained in:
parent
3fef57df8a
commit
e7c140a319
17 changed files with 41 additions and 4 deletions
2
a.sql
2
a.sql
|
@ -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
|
select firstName, lastName
|
||||||
from Students
|
from Students
|
2
b.sql
2
b.sql
|
@ -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
|
select firstName, lastName
|
||||||
from Students
|
from Students
|
||||||
order by lastName, firstName
|
order by lastName, firstName
|
2
c.sql
2
c.sql
|
@ -1,3 +1,5 @@
|
||||||
|
--Which students were born in 1975?
|
||||||
|
|
||||||
select firstName, lastName
|
select firstName, lastName
|
||||||
from Students
|
from Students
|
||||||
where pNbr like '1975%'
|
where pNbr like '1975%'
|
3
d.sql
3
d.sql
|
@ -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
|
select firstName, pNbr
|
||||||
from Students
|
from Students
|
||||||
where substring(pNbr, LENGTH(pNbr) -1, 1) % 2 = 0
|
where substring(pNbr, LENGTH(pNbr) -1, 1) % 2 = 0
|
4
e.sql
4
e.sql
|
@ -1,2 +1,4 @@
|
||||||
select distinct pNbr
|
--How many students are registered in the database?
|
||||||
|
|
||||||
|
select count(*)
|
||||||
from Students
|
from Students
|
3
f.sql
3
f.sql
|
@ -1,3 +1,6 @@
|
||||||
|
--Which courses are offered by the department of Mathematics
|
||||||
|
--(course codes FMAxxx)? [24]
|
||||||
|
|
||||||
select courseName
|
select courseName
|
||||||
from Courses
|
from Courses
|
||||||
where courseCode like '%FMA%'
|
where courseCode like '%FMA%'
|
2
g.sql
2
g.sql
|
@ -1,3 +1,5 @@
|
||||||
|
--Which courses give more than five credits? [21]
|
||||||
|
|
||||||
select courseName
|
select courseName
|
||||||
from Courses
|
from Courses
|
||||||
where credits > 5
|
where credits > 5
|
3
h.sql
3
h.sql
|
@ -1,3 +1,6 @@
|
||||||
|
--Which courses (course codes only) have been taken by the student with person
|
||||||
|
--num-ber 790101-1234? [7]
|
||||||
|
|
||||||
select courseCode
|
select courseCode
|
||||||
from TakenCourses
|
from TakenCourses
|
||||||
where pNbr = '790101-1234'
|
where pNbr = '790101-1234'
|
2
i.sql
2
i.sql
|
@ -1,3 +1,5 @@
|
||||||
|
--What are the names of these courses, and how many credits do they give?
|
||||||
|
|
||||||
select courseName, credits, courseCode, pNbr
|
select courseName, credits, courseCode, pNbr
|
||||||
from Courses
|
from Courses
|
||||||
join Students on Students.pNbr
|
join Students on Students.pNbr
|
||||||
|
|
2
j.sql
2
j.sql
|
@ -1,3 +1,5 @@
|
||||||
|
--How many credits has the student taken?
|
||||||
|
|
||||||
select sum(credits) as totalSum
|
select sum(credits) as totalSum
|
||||||
from Courses
|
from Courses
|
||||||
join Students on Students.pNbr
|
join Students on Students.pNbr
|
||||||
|
|
2
k.sql
2
k.sql
|
@ -1,3 +1,5 @@
|
||||||
|
--Which is the student’s grade average on the courses that he has taken?
|
||||||
|
|
||||||
select avg(TakenCourses.grade) as averageGrade, Students.pNbr
|
select avg(TakenCourses.grade) as averageGrade, Students.pNbr
|
||||||
from TakenCourses
|
from TakenCourses
|
||||||
join Students on TakenCourses.pNbr = Students.pNbr
|
join Students on TakenCourses.pNbr = Students.pNbr
|
||||||
|
|
2
l.sql
2
l.sql
|
@ -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
|
select firstName, lastName, avg(TakenCourses.grade) as averageGrade, TakenCourses.courseCode, Courses.courseName, sum(Courses.credits) as totalCredits
|
||||||
from TakenCourses
|
from TakenCourses
|
||||||
join Students on TakenCourses.pNbr = Students.pNbr
|
join Students on TakenCourses.pNbr = Students.pNbr
|
||||||
|
|
4
m.sql
4
m.sql
|
@ -1,4 +1,6 @@
|
||||||
select distinct firstName
|
--Which students have taken 0 credits? [16]
|
||||||
|
|
||||||
|
select firstName, lastName
|
||||||
from Students
|
from Students
|
||||||
left join TakenCourses on Students.pNbr = TakenCourses.pNbr
|
left join TakenCourses on Students.pNbr = TakenCourses.pNbr
|
||||||
where TakenCourses.pNbr is null
|
where TakenCourses.pNbr is null
|
3
n.sql
3
n.sql
|
@ -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;
|
DROP VIEW IF EXISTS StudentsAverages;
|
||||||
|
|
||||||
CREATE VIEW StudentsAverages AS
|
CREATE VIEW StudentsAverages AS
|
||||||
|
|
3
o.sql
3
o.sql
|
@ -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;
|
DROP VIEW IF EXISTS StudentsCredits;
|
||||||
|
|
||||||
CREATE VIEW StudentsCredits AS
|
CREATE VIEW StudentsCredits AS
|
||||||
|
|
4
p.sql
4
p.sql
|
@ -1,7 +1,9 @@
|
||||||
|
--Same question as in question o) but with names instead of person numbers.
|
||||||
|
|
||||||
DROP VIEW IF EXISTS StudentsCredits;
|
DROP VIEW IF EXISTS StudentsCredits;
|
||||||
|
|
||||||
CREATE VIEW StudentsCredits AS
|
CREATE VIEW StudentsCredits AS
|
||||||
SELECT Students.firstName, sum(credits) as totalCredits
|
SELECT Students.firstName, Students.lastName, sum(credits) as totalCredits
|
||||||
FROM Students
|
FROM Students
|
||||||
JOIN TakenCourses ON Students.pNbr = TakenCourses.pNbr
|
JOIN TakenCourses ON Students.pNbr = TakenCourses.pNbr
|
||||||
JOIN Courses ON TakenCourses.courseCode = Courses.courseCode
|
JOIN Courses ON TakenCourses.courseCode = Courses.courseCode
|
||||||
|
|
2
q.sql
2
q.sql
|
@ -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
|
SELECT firstName, lastName, count(*) as nbrOfStudents
|
||||||
FROM Students
|
FROM Students
|
||||||
GROUP BY firstName, lastName
|
GROUP BY firstName, lastName
|
||||||
|
|
Loading…
Reference in a new issue