Directions (Q96–100): Use the following schema of an academic institution's relational database:
student (rollno, name, degree, year, sex, deptno, advisor) department (deptid, name, hod, phone) professor (empid, name, sex, startyear, deptno, phone) course (courseid, cname, credits, deptno) enrollment (rollno, courseid, sem, year, grade) teaching (empid, courseid, sem, year, classroom) prerequisite (precourseid, courseid)
deptno in student, professor and course refers to department.deptid; advisor (student) and hod (department) refer to professor.empid; rollno in enrollment refers to student; courseid in enrollment and teaching refers to course; empid in teaching refers to professor; precourseid and courseid in prerequisite refer to course.
Which of the following queries computes, for each department, the total credits of all the courses offered by the department?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: A.
SELECT deptid, name, SUM(credits) AS totalcredits FROM department, course WHERE deptid = deptno GROUP BY deptid, name;
Explanation
Join on deptid = deptno in WHERE, group by department, and SUM the credits. COUNT counts courses; C has no join or grouping; D filters the join after grouping, which is invalid.More Database Management Systems questions
- Which of the following queries retrieves the deptid and name of all departments whose total credits of offered courses is strictly greater…
- Given the query SELECT s.rollno, s.name FROM student s WHERE EXISTS (SELECT c.courseid FROM course c WHERE c.deptno = 5 AND EXISTS (SELECT…
- Identify the incorrect statement.
- Consider the two relations below (primary keys: EMP.eid and DEPT.did). Identify all possible foreign key(s) based only on the two relations…
- Which of the following statements is correct according to the following instance of the relational schema R(X, Y, Z)?X Y Z 1 1 a 1 1 a 2 1…
- What are the drawbacks of using file systems to store data? 1. Data inconsistency 2. Difficulty in accessing data 3. Data isolation 4. Atom…