Question

CREATE TABLE Majors major VARCHAR(12), description VARCHAR, PRIMARY KEY (major) ); CREATE TABLE Course ( courseMajor VARCHAR(Given the schema, write a query and subquery to do the following:

Find the Cpts major students who passed a course but failed the prerequisite of that course, i.e., got a grade lower than

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution==> Please do comment in case of any query.

Step1:- First we need to select all the courses from table Enroll where courseMajor = "CptS". SQL for this is :-

  select * from enroll where courseMajor ="CptS";

Step2:- Now we need to perform inner join with table Prereq . I have created dummy database for your better understanding. SQL for this is :-

select * from enroll e inner join Prereq p on e.courseMajor = p.courseMajor and e.courseNo = p.courseNo;

Number of Records: 3 courseMajor courseNo SID grade preMajor preCourseNo Cpts 255 12583589 Cpto 155 Cpts 231 12583589 Cpto 13

Step 3 :- Now we need to find grade in preMajor Courses. SQL for this:-

select A.courseMajor, A.courseNo, A.sID, A.preMajor, A.preCourseNo, B.grade from (select * from enroll e inner join Prereq p on e.courseMajor = p.courseMajor and e.courseNo = p.courseNo) A inner join enroll B on A.preMajor = B.courseMajor and A.preCourseNo = B.CourseNo ;

Number of Records: 3 courseMajor courseNo SID preMajor preCourseNo grade Cpts 255 12583589 Cpto 155 Cpts 231 12583589 Cpto 13

Step 4:- Now we need to get the name of the students.SQL is :-

  select D.sname, C.sID , C.courseMajor, C.courseNo from ( select A.courseMajor, A.courseNo, A.sID, A.preMajor, A.preCourseNo, B.grade from (select * from enroll e inner join Prereq p on e.courseMajor = p.courseMajor and e.courseNo = p.courseNo ) A inner join enroll B on A.preMajor = B.courseMajor and A.preCourseNo = B.CourseNo ) C inner join Student D on D.sID = C.sID;

sName SID courseMajor courseNo Alice 12583589 Cpts 255 Alice 12583589 Cpts 231 Alice 12583589 Cpts 223

Step 5:- Filter on the basis of grade.SQL is:-

select D.sname, C.sID , C.courseMajor, C.courseNo from ( select A.courseMajor, A.courseNo, A.sID, A.preMajor, A.preCourseNo, B.grade from (select * from enroll e inner join Prereq p on e.courseMajor = p.courseMajor and e.courseNo = p.courseNo where e.courseMajor = "CptS" ) A inner join enroll B on A.preMajor = B.courseMajor and A.preCourseNo = B.CourseNo ) C inner join Student D on D.sID = C.sID where C.grade < 2;

Number of Records: 2 sName SID courseMajor course No Alice 12583589 Cpts 223 Alice 12583589 Cpts 231

Result SQL:-

select D.sname, C.sID , C.courseMajor, C.courseNo from ( select A.courseMajor, A.courseNo, A.sID, A.preMajor, A.preCourseNo, B.grade from (select * from enroll e inner join Prereq p on e.courseMajor = p.courseMajor and e.courseNo = p.courseNo where e.courseMajor = "CptS" ) A inner join enroll B on A.preMajor = B.courseMajor and A.preCourseNo = B.CourseNo ) C inner join Student D on D.sID = C.sID where C.grade < 2;

Hope you will like the answer.

Thanks.

Add a comment
Know the answer?
Add Answer to:
Given the schema, write a query and subquery to do the following: CREATE TABLE Majors major...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • /* I am executing following SQL statement for the below code but I am getting error....

    /* I am executing following SQL statement for the below code but I am getting error. Pls, upload screenshot after running it. SQL Statement: SELECT OfferNo, CourseNo FROM Offering WHERE OfferTerm = 'Sum' AND OfferYear = 2012 AND FacSSN IS NULL; */ CREATE TABLE STUDENT( StdSSN INT NOT NULL PRIMARY KEY, StdFName VARCHAR2(50), StdLName VARCHAR2(50), StdCity VARCHAR2(50), StdState VARCHAR2(2), StdZip VARCHAR2(10), StdMajor VARCHAR2(15), StdYear VARCHAR2(20) ); CREATE TABLE FACULTY( FacSSN INTEGER NOT NULL PRIMARY KEY, FacFName VARCHAR(50), FacLName VARCHAR(50), FacCity...

  • Write an SQL query to return the users who posted the most number of jokes on...

    Write an SQL query to return the users who posted the most number of jokes on 1/1/2019. Database: create table User( userid varchar(30) not null, password varchar(30), firstname varchar(30), lastname varchar(50), email varchar(50), gender char(1), age integer, banned boolean, primary key(userid), unique(email)); create table MyFriends( userid varchar(30), friendid varchar(30), primary key(userid,friendid), foreign key(userid) references User, foreign key(friendid) references User(userid)); Create table Jokes( Jokeid integer, title varchar(100), description varchar(255), authorid varchar(30) not null, primary key(jokeid), posttime Datetime, foreign key(authorid) references User(userid));...

  • Given the mySQL tables created below...    Create a mySQL solution to return the itemIDs of...

    Given the mySQL tables created below...    Create a mySQL solution to return the itemIDs of items posted by user X, such that all the reviews are “Excellent” or “Good” for these items CREATE TABLE Users (    userId varchar (30) NOT NULL,    pass varchar (30),    fname varchar (50),    lname varchar (50),    email varchar (50),    gender char(1),    age integer,    banned boolean,    PRIMARY KEY (userId),    UNIQUE(email)) CREATE TABLE FavSellers (    userId...

  • SQL Query Question: I have a database with the tables below, data has also been aded...

    SQL Query Question: I have a database with the tables below, data has also been aded into these tables, I have 2 tasks: 1. Add a column to a relational table POSITIONS to store information about the total number of skills needed by each advertised position. A name of the column is up to you. Assume that no more than 9 skills are needed for each position. Next, use a single UPDATE statement to set the values in the new...

  • Based on reference below. Write a relational algebra expression to return those users who have posted...

    Based on reference below. Write a relational algebra expression to return those users who have posted “excellent” reviews but never “poor” reviews. CREATE TABLE Users (             userId varchar (30) NOT NULL,             pass varchar (30),             fname varchar (50),             lname varchar (50),             email varchar (50),             gender char(1),             age integer,             banned boolean,             PRIMARY KEY (userId),             UNIQUE(email)) CREATE TABLE FavSellers (             userId varchar (30),             sellerId varchar (30),             PRIMARY KEY (userId, sellerId),...

  • Database concepts Find the names and ids of the students who have taken at most one...

    Database concepts Find the names and ids of the students who have taken at most one course in the Spring 2010 semester. Notice, at most one means one or zero. So, the answer should include students who did not take any course during that semester The data: create table classroom     (building       varchar(15),      room_number        varchar(7),      capacity       numeric(4,0),      primary key (building, room_number)     ); create table department     (dept_name      varchar(20),      building       varchar(15),      budget      numeric(12,2) check (budget > 0),      primary key (dept_name)     ); create...

  • Utilize the JigSaw SQL file below to create a Star Schema diagram. Remember, to create a...

    Utilize the JigSaw SQL file below to create a Star Schema diagram. Remember, to create a Star Schema from a normalized data model, you will need to denormalize the data model into fact and dimension tables. The diagram should contain all of the facts and dimension tables necessary to integrate the JigSaw operational database into a data warehouse. Write a brief paper describing the challenges you experienced in completing this assignment. -- CREATE DATABASE js; CREATE TABLE buy_methods ( buy_code...

  • -- Schema definition create table Customer (     cid   smallint not null,     name varchar(20),    ...

    -- Schema definition create table Customer (     cid   smallint not null,     name varchar(20),     city varchar(15),     constraint customer_pk         primary key (cid) ); create table Club (     club varchar(15) not null,     desc varchar(50),     constraint club_pk         primary key (club) ); create table Member (     club varchar(15) not null,     cid   smallint     not null,     constraint member_pk         primary key (club, cid),     constraint mem_fk_club         foreign key (club) references Club,     constraint mem_fk_cust...

  • This is database system concept. 1.Find the ids of instructors who are also students using a...

    This is database system concept. 1.Find the ids of instructors who are also students using a set operation. Assume that a person is identified by her or his id. So, if the same id appears in both instructor and student, then that person is both an instructor and a student. Remember: set operation means union, intersect or set difference. 2.Find the ids of instructors who are also students using the set membership operator. 3.Find the ids of instructors who are...

  • You will create the following 4 triggers: - trgEmployee: Will be placed on the Employee table...

    You will create the following 4 triggers: - trgEmployee: Will be placed on the Employee table and listens for Inserts, Deletes, and Updates - trgJob: Will be placed on the Job table and listens for Inserts, Deletes, and Updates - trgProject: Will be placed on the Project table that contains the projectId and projectName. - trgActivity: Will be placed on the Activity table that contains the activityId and activityName. Again, each trigger will write to its respective audit table: trgProject...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT