0% found this document useful (0 votes)
13 views8 pages

Databaseprint 69

The document outlines a series of SQL queries designed to retrieve various educational data from a database schema involving students, courses, enrollments, instructors, and teaching assignments. Key queries include finding average grades, identifying students enrolled in multiple courses, and listing courses with no enrollments. The document also includes relational algebra expressions for similar data retrieval tasks.

Uploaded by

jabikoi314
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

Databaseprint 69

The document outlines a series of SQL queries designed to retrieve various educational data from a database schema involving students, courses, enrollments, instructors, and teaching assignments. Key queries include finding average grades, identifying students enrolled in multiple courses, and listing courses with no enrollments. The document also includes relational algebra expressions for similar data retrieval tasks.

Uploaded by

jabikoi314
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Schema:

Student: (StudentID, Name, Email, Major)

Course: (CourseID, Name, Credits, Department)

Enrollment: (StudentID, CourseID, Semester, Grade)

Instructor: (InstructorID, Name, Email, Department)

Teaches: (InstructorID, CourseID, Semester)

1. Retrieve the average grade for all students across all courses.
sql
Copy code
SELECT AVG(Grade) AS AverageGrade
FROM Enrollment;

2. Find all students who are enrolled in more than three courses in a single
semester.
sql
Copy code
SELECT StudentID, Semester
FROM Enrollment
GROUP BY StudentID, Semester
HAVING COUNT(CourseID) > 3;

3. List the names of students who have never enrolled in any course.
sql
Copy code
SELECT Name
FROM Student
WHERE StudentID NOT IN (
SELECT DISTINCT StudentID
FROM Enrollment
);

4. Retrieve the details of courses that have no students enrolled in them.


sql
Copy code
SELECT *
FROM Course
WHERE CourseID NOT IN (
SELECT DISTINCT CourseID
FROM Enrollment
);
5. Find the names of students who have achieved a grade of "A" in at least
two courses.
sql
Copy code
SELECT S.Name
FROM Student S
JOIN Enrollment E ON S.StudentID = E.StudentID
WHERE E.Grade = 'A'
GROUP BY S.StudentID, S.Name
HAVING COUNT(E.CourseID) >= 2;

6. List the courses that are taught by more than one instructor in the same
semester.
sql
Copy code
SELECT CourseID, Semester
FROM Teaches
GROUP BY CourseID, Semester
HAVING COUNT(DISTINCT InstructorID) > 1;

7. Retrieve the names of instructors who teach courses in multiple


departments.
sql
Copy code
SELECT DISTINCT I.Name
FROM Instructor I
JOIN Teaches T ON I.InstructorID = T.InstructorID
JOIN Course C ON T.CourseID = C.CourseID
GROUP BY I.InstructorID, I.Name
HAVING COUNT(DISTINCT C.Department) > 1;

8. Find the students who have enrolled in both "Database Systems" and
"Operating Systems."
sql
Copy code
SELECT S.Name
FROM Student S
JOIN Enrollment E1 ON S.StudentID = E1.StudentID
JOIN Course C1 ON E1.CourseID = C1.CourseID
JOIN Enrollment E2 ON S.StudentID = E2.StudentID
JOIN Course C2 ON E2.CourseID = C2.CourseID
WHERE C1.Name = 'Database Systems' AND C2.Name = 'Operating Systems';
9. Retrieve the details of students majoring in "Computer Science" who have
earned an average grade greater than 3.5 across all their courses.
sql
Copy code
SELECT S.*
FROM Student S
JOIN Enrollment E ON S.StudentID = E.StudentID
WHERE S.Major = 'Computer Science'
GROUP BY S.StudentID, S.Name, S.Email, S.Major
HAVING AVG(E.Grade) > 3.5;

10. List the names of instructors who have not taught any courses during the
Fall 2024 semester.
sql
Copy code
SELECT Name
FROM Instructor
WHERE InstructorID NOT IN (
SELECT DISTINCT InstructorID
FROM Teaches
WHERE Semester = 'Fall 2024'
);

11. Retrieve the names of students enrolled in the most number of courses
during the Spring 2024 semester.
sql
Copy code
SELECT S.Name
FROM Student S
JOIN Enrollment E ON S.StudentID = E.StudentID
WHERE E.Semester = 'Spring 2024'
GROUP BY S.StudentID, S.Name
HAVING COUNT(E.CourseID) = (
SELECT MAX(CourseCount)
FROM (
SELECT COUNT(CourseID) AS CourseCount
FROM Enrollment
WHERE Semester = 'Spring 2024'
GROUP BY StudentID
) AS Temp
);

12. Find the details of the course with the highest number of students enrolled
in the Fall 2024 semester.
sql
Copy code
SELECT C.*
FROM Course C
JOIN Enrollment E ON C.CourseID = E.CourseID
WHERE E.Semester = 'Fall 2024'
GROUP BY C.CourseID, C.Name, C.Credits, C.Department
ORDER BY COUNT(E.StudentID) DESC
LIMIT 1;

13. Retrieve the names of students who have taken at least one course from
the "Mathematics" department.
sql
Copy code
SELECT DISTINCT S.Name
FROM Student S
JOIN Enrollment E ON S.StudentID = E.StudentID
JOIN Course C ON E.CourseID = C.CourseID
WHERE C.Department = 'Mathematics';

14. Find the average number of credits earned by students majoring in


"Physics."
sql
Copy code
SELECT AVG(C.Credits) AS AverageCredits
FROM Student S
JOIN Enrollment E ON S.StudentID = E.StudentID
JOIN Course C ON E.CourseID = C.CourseID
WHERE S.Major = 'Physics';

15. Retrieve the details of courses that are worth more than the average
number of credits.
sql
Copy code
SELECT *
FROM Course
WHERE Credits > (
SELECT AVG(Credits)
FROM Course
);

16. Find the names of students who have not achieved a grade lower than "B"
in any course.
sql
Copy code
SELECT DISTINCT S.Name
FROM Student S
JOIN Enrollment E ON S.StudentID = E.StudentID
WHERE E.Grade NOT IN ('C', 'D', 'F')
GROUP BY S.StudentID, S.Name
HAVING COUNT(*) = (
SELECT COUNT(*)
FROM Enrollment E2
WHERE E2.StudentID = S.StudentID
);

17. Retrieve the details of instructors who have taught courses only in the
"Engineering" department.
sql
Copy code
SELECT I.*
FROM Instructor I
JOIN Teaches T ON I.InstructorID = T.InstructorID
JOIN Course C ON T.CourseID = C.CourseID
GROUP BY I.InstructorID, I.Name, I.Email, I.Department
HAVING COUNT(DISTINCT C.Department) = 1 AND MAX(C.Department) =
'Engineering';

18. List the courses that have been offered in every semester.
sql
Copy code
SELECT C.CourseID, C.Name
FROM Course C
JOIN Teaches T ON C.CourseID = T.CourseID
GROUP BY C.CourseID, C.Name
HAVING COUNT(DISTINCT T.Semester) = (
SELECT COUNT(DISTINCT Semester)
FROM Teaches
);

19. Retrieve the names of students who have been taught by "Dr. Alice
Green" in any semester.
sql
Copy code
SELECT DISTINCT S.Name
FROM Student S
JOIN Enrollment E ON S.StudentID = E.StudentID
JOIN Teaches T ON E.CourseID = T.CourseID
JOIN Instructor I ON T.InstructorID = I.InstructorID
WHERE I.Name = 'Dr. Alice Green';

20. Find the department with the highest average grade for its courses.
sql
Copy code
SELECT C.Department
FROM Course C
JOIN Enrollment E ON C.CourseID = E.CourseID
GROUP BY C.Department
ORDER BY AVG(E.Grade) DESC
LIMIT 1;
Schema:

Student: (StudentID, Name, Email, Major)

Course: (CourseID, Name, Credits, Department)

Enrollment: (StudentID, CourseID, Semester, Grade)

Instructor: (InstructorID, Name, Email, Department)

Teaches: (InstructorID, CourseID, Semester)

1. Retrieve the names of students enrolled in the course named "Database Systems" in
Fall 2024.
Answer:
πStudent.Name(σCourse.Name=′DatabaseSystems′∧Enrollment.Semester=′Fall2024′(
Student⋈Enrollment⋈Course))

2. List all courses offered by the "Computer Science" department.


Answer:
πName(σDepartment=′ComputerScience′(Course))

3. Find the total number of courses taken by each student.


Answer:
πStudentID,count(CourseID)(γStudentID;count(CourseID)(Enrollment))

4. List all students taught by the instructor named "Dr. John Smith."
Answer:
πStudent.Name(σInstructor.Name=′Dr.JohnSmith′(Student⋈Enrollment⋈Teaches⋈I
nstructor))

5. Retrieve the details of students who have taken more than three courses in a single
semester.
Answer:
πStudentID,Name,Email,Major(σcount(CourseID)>3(γStudentID,Semester;count(Cou
rseID)(Enrollment)⋈Student))

6. Retrieve the names of instructors who teach in multiple departments.


Answer:
πName(σcount(distinct
Department)>1(γInstructorID;count(Department)(Instructor⋈Teaches)))

7. List all students with a grade of "A" in any course during the Spring 2024 semester.
Answer:
πName(σGrade=′A′∧Semester=′Spring2024′(Student⋈Enrollment))

8. Find the total credits earned by each student in Fall 2024.


Answer:
πStudentID,sum(Credits)(γStudentID;sum(Credits)(σEnrollment.Semester=′Fall2024′
(Enrollment⋈Course)))

9. Retrieve the details of courses not taught by any instructor in the Spring 2024
semester.
Answer:
Course−πCourseID,Name,Credits,Department(σTeaches.Semester=′Spring2024′(Cour
se⋈Teaches))

10. List all instructors who have taught the course named "Machine Learning."
Answer:
πInstructor.Name(σCourse.Name=′MachineLearning′(Instructor⋈Teaches⋈Course))
11. Retrieve the names of students majoring in "Data Science" who are enrolled in any
"Computer Science" course.
Answer:
πStudent.Name(σStudent.Major=′DataScience′∧Course.Department=′ComputerScien
ce′(Student⋈Enrollment⋈Course))

12. Find the average grade for the course named "Introduction to Programming."
Answer:
πavg(Grade)(γavg(Grade)(σCourse.Name=′IntroductiontoProgramming′(Enrollment
⋈Course)))

13. Retrieve the details of students who have not enrolled in any course during the Spring
2024 semester.
Answer:
Student−πStudentID,Name,Email,Major(σEnrollment.Semester=′Spring2024′(Student
⋈Enrollment))

14. List all courses with at least five students enrolled in the Fall 2024 semester.
Answer:
πCourseID,Name(σcount(StudentID)≥5(γCourseID;count(StudentID)(σEnrollment.Se
mester=′Fall2024′(Enrollment))))

15. Retrieve the details of instructors who have not taught any courses during the past
year.
Answer:
Instructor−πInstructorID,Name,Email,Department(σTeaches.Semester∈{′Spring2024′
,′Fall2024′}(Instructor⋈Teaches))

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy