Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This assignment is about using SQL to write queries. The university database has

ID: 3820091 • Letter: T

Question

This assignment is about using SQL to write queries.

The university database has the following schema. This is intended to be used for a single year and semester. Primary keys are underlined. The relationships between tables are as you know. bullet STUDENT(SSN, SNAME, MAJOR, DOB, ADDRESS) bullet COURSE (CID, CNAME, CREDIT) bullet ENROLLED (SSN, CID, GRADE) bullet FACULTY (SSN, NAME, DOB) bullet TEACHING (FACULTYSSN, CID) bullet PREQ(CID, PREREQUISITECID, PASSINGGRADE) Write each query in SQL: What are the names of students who enrolled in a course without enrolling in that course's prerequisite? What is the most popular major? Retrieve a summary: for each prerequisite course id, show the number of courses that require it as a prerequisite course What are the names of courses that have at least two prerequisites? What are the names of courses that have less than five students enrolled in? What are the names of faculties who teach a course and also its prerequisite Course? Write a series of SQL statements for creating the university database completely. Each statement ends with a semicolon. The statements need to be in a proper order, so that the foreign key referent exists before the foreign key declaration. Please use appropriate data types.

Explanation / Answer

Please give thumbs up, If it is helpful for you. Thankyou!!

a)
SELECT SNAME
FROM STUDENT AS S INNER JOIN ENROLLED AS E
ON S.SSN = E.SSN
INNER JOIN PREQ P ON E.CID != P.CID;

b)
SELECT MAJOR FROM
(SELECT MAJOR, COUNT(*)
FROM STUDENT GROUP BY MAJOR
ORDER BY COUNT(*) DESC LIMIT 1) AS T;

c)
SELECT PREREQUICITECID, CONT(CID) as NO_OF_COURSES
FROM PREQ
GROUP BY PREREQUICITECID;

d)
SELECT CNAME
FROM COURSE AS C INNERJOIN
(SELECT CID, COUNT(PREREQUICITECID) AS CNT
FROM PREQ GROUP BY CID HAVING CNT >= 2) AS T
ON C.CID = T.CID;

e)
SELECT CNAME
FROM COURSE AS C INNERJOIN
(SELECT CID, COUNT(SSN) AS NO_OF_SSN
FROM ENROLLED GROUP BY CID HAVING NO_OF_SSN < 5) AS T
ON C.CID = T.CID;

f)
SELECT F.NAME
FROM FACULTY AS F INNER JOIN TEACHING AS T
ON F.SSN = T.FACULTYSSN
INNER JOIN PREQ AS P
ON T.CID = P.CID AND T.CID = P.PREREQUICITECID;