0% found this document useful (0 votes)
43 views3 pages

Database

The document contains a series of SQL queries related to student enrollments, grades, and course information. It includes operations such as counting students per course, filtering students based on grades, and retrieving course names based on student performance. The queries also explore relationships between students, courses, and departments in a database context.

Uploaded by

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

Database

The document contains a series of SQL queries related to student enrollments, grades, and course information. It includes operations such as counting students per course, filtering students based on grades, and retrieving course names based on student performance. The queries also explore relationships between students, courses, and departments in a database context.

Uploaded by

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

1.

SELECT CourseID, COUNT(StudentID) FROM enrollments GROUP BY CourseID

2. SELECT StudentID FROM enrollments WHERE Grade = 'A'

3. SELECT StudentID, CourseID FROM enrollments WHERE CourseID IN (SELECT CourseID FROM
courses WHERE Credits > 3);

4. SELECT CourseID FROM enrollments WHERE StudentID IS NULL

5. SELECT CourseID FROM enrollments WHERE StudentID = (SELECT StudentID FROM students W
HERE Name = 'Eva Green')

6. SELECT Name
7. FROM Students
8. WHERE StudentID IN (
9. SELECT StudentID
10. FROM Enrollments
11. WHERE CourseID = (
12. SELECT CourseID
13. FROM Courses
14. WHERE CourseName = 'Database Systems'
15. )
16. )
17. AND StudentID IN (
18. SELECT StudentID
19. FROM Enrollments
20. WHERE CourseID = (
21. SELECT CourseID
22. FROM Courses
23. WHERE CourseName = 'Data Structures'
24. )
25. );

7. SELECT StudentID FROM enrollments WHERE Grade = 'B';


8. SELECT enrollments.StudentID, Grade, CourseName FROM enrollments, courses, students
WHERE courses.CourseID = enrollments.CourseID AND enrollments.StudentID =
students.StudentID ORDER BY students.GPA DESC;
9. SELECT COUNT(DISTINCT StudentID), enrollments.CourseID, Department FROM enrollments,
courses WHERE courses.CourseID = enrollments.CourseID GROUP BY enrollments.CourseID,
courses.Department;
10. SELECT CourseID, COUNT(StudentID) AS StudentCount FROM enrollments GROUP BY
CourseID ORDER BY StudentCount DESC;
11. SELECT StudentID FROM enrollments GROUP BY StudentID HAVING COUNT(CourseID) = 1;
12. SELECT students.Name, enrollments.CourseID FROM students, enrollments WHERE
enrollments.StudentID != students.StudentID GROUP BY students.StudentID;
13. SELECT StudentID FROM students WHERE GPA < (SELECT MAX(GPA) FROM students) LIMIT 1;
14. SELECT Department FROM courses WHERE CourseID = (SELECT enrollments.CourseID FROM
enrollments ORDER BY COUNT(enrollments.StudentID) DESC LIMIT 1);
15. SELECT Name FROM Students WHERE StudentID NOT IN (SELECT DISTINCT StudentID FROM
Enrollments);
16. SELECT c.CourseName, COUNT(e.StudentID) AS StudentCount FROM Courses c LEFT JOIN
Enrollments e ON c.CourseID = e.CourseID GROUP BY c.CourseID, c.CourseName;
17. SELECT Name FROM Students WHERE GPA > (SELECT AVG(GPA) FROM Students);
20. SELECT Name
18. FROM Students
19. WHERE StudentID NOT IN (
20. SELECT DISTINCT e.StudentID
21. FROM Enrollments e
22. WHERE e.CourseID IN (
23. SELECT c.CourseID
24. FROM Courses c
25. WHERE c.Department = 'Math'
26. )
27. );

21. SELECT c.CourseName


22. FROM Courses c
23. WHERE c.CourseID IN (
24. SELECT e.CourseID
25. FROM Enrollments e
26. WHERE e.StudentID = (
27. SELECT StudentID
28. FROM Students
29. WHERE GPA = (SELECT MAX(GPA) FROM Students)
30. )
31. );

22. SELECT Name


23. FROM Students
24. WHERE GPA > 3.0
25. AND StudentID NOT IN (
26. SELECT DISTINCT StudentID
27. FROM Enrollments
28. );

23. SELECT c.Department


24. FROM Courses c
25. LEFT JOIN Enrollments e ON c.CourseID = e.CourseID
26. GROUP BY c.Department
27. ORDER BY COUNT(e.StudentID) ASC
28. LIMIT 1;

24. SELECT s.Name


25. FROM Students s
26. WHERE NOT EXISTS (
27. SELECT c.CourseID
28. FROM Courses c
29. WHERE c.Department = s.Department
30. AND c.CourseID NOT IN (
31. SELECT e.CourseID
32. FROM Enrollments e
33. WHERE e.StudentID = s.StudentID
34. )
35. );

25 SELECT s.Name
FROM Students s
WHERE s.StudentID IN (
SELECT e.StudentID
FROM Enrollments e
GROUP BY e.StudentID
HAVING COUNT(e.CourseID) = (
SELECT MAX(course_count)
FROM (
SELECT COUNT(CourseID) AS course_count
FROM Enrollments
GROUP BY StudentID
) AS course_counts
)
);

You might also like