Need more help with Oracle SQL problems Generate an alphabetic listing containin
ID: 3733432 • Letter: N
Question
Need more help with Oracle SQL problems
Generate an alphabetic listing containing the last names and final exam grade (FI) of students who scored above average on the final exam for section 90.
List the course number and course description of the courses with the lowest number of enrolled students. Arrange the list on course number.
Explanation / Answer
1) For this query 4 tables namely STUDENT, GRADE, ENROLLMENT, SECTION are joined based on the common attribute. Aggregate function SUM is used to get student wise grade summation, then in HAVING clause this is compared with the average grade. WHERE clause is used to filter section no 90. To sorted the result in ascending order of student last name ORDER by clause is used.
Query-
SELECT s.LAST_NAME, SUM(g.NUMERIC_GRADE)
FROM STUDENT AS s
INNER JOIN GRADE AS g
ON g.STUDENT_ID = s.STUDENT_ID
INNER JOIN ENROLLMENT AS e
ON e.STUDENT_ID = s.STUDENT_ID
INNER JOIN SECTION AS se
ON se.SECTION_ID = e.SECTION_ID
WHERE se.SECTION_NO = 90
GROUP BY s.LAST_NAME, s.FIRST_NAME
HAVING SUM(g.NUMERIC_GRADE) > AVG(g.NUMERIC_GRADE)
ORDER BY s.LAST_NAME;
2) For this 3 tables namely COURSE, SECTION and ENROLLMENT are joined on common attribute. Aggregate function COUNT is used to count the number of student in each course. In having clause this number is compared with the average enrollment of the student, if it is less then average then it is considered as minimal student enrollment.
Query-
SELECT c.COURSE_NO, c.DESCRIPTION, COUNT(e.STUDENT_ID) AS "Enrolled"
FROM COURSE AS c
INNER JOIN SECTION AS se
ON se.COURSE_NO = c.COURSE_NO
INNER JOIN ENROLLMENT AS e
ON e.SECTION_ID = se.SECTION_ID
GROUP BY c.COURSE_NO, c.DESCRIPTION
HAVING COUNT(e.STUDENT_ID) < (SELECT AVG(COUNT(STUDENT_ID)) FROM ENROLLMENT);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.