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 retrieves the deptid and name of all departments whose total credits of offered courses is strictly greater than 40?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: D.
SELECT deptid, name, SUM(credits) AS totalcredits FROM department, course WHERE deptid = deptno GROUP BY deptid, name HAVING totalcredits > 40;
Explanation
Join conditions belong in WHERE, and conditions on aggregates belong in HAVING after GROUP BY.More Database Management Systems questions
- 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…
- In which of the following database models do we have a parent-child relationship? 1. Hierarchical databases 2. Network databases 3. Relatio…