Ans Assignment2b

May 5, 2017 | Author: Murugan Ramachandran Pillai R | Category: N/A
Share Embed Donate


Short Description

Download Ans Assignment2b...

Description

Assignment 2b

1. Find the id and title of all courses which do not require any prerequisites. Ans: select distinct course.course_id, title from course, prereq where course.course_id not in (select course_id from prereq); Output: "CS-101"; "PHY-101"; "BIO-101"; "FIN-201"; "HIS-351"; "MU-199";

"Intro. to Computer Science" "Physical Principles" "Intro. to Biology" "Investment Banking" "World History" "Music Video Production"

2. Find the names of students who have not taken any biology dept courses Ans: select distinct student.name from student left outer join takes on student.id = takes.id and student.dept_name'Biology'; Output: "Zhang" "Shankar" "Bourikas" "Chavez" "Snow" "Brown" "Brandt" "Peltier" "Sanchez" "Levy" "Williams" "Aoi"

3. Write SQL update queries to perform the following (queries 2 and 4 are pretty meangless, but still fun to write): 1. Give a 10% hike to all instructors Ans: update instructor set salary=salary*1.1; 2. Increase the tot_creds of all students who have taken the course titled "Genetics" by the number of credits associated with that course. Ans: update student set tot_cred = tot_cred + (select credits from course, takes where course.course_id=takes.course_id and title='Genetics') from course, takes where course.course_id=takes.course_id and course.title='Genetics' and takes.id=student.id; 3. For all instructors who are advisors of atleast 2 students, increase their salary by 50000. Ans: update instructor set salary = salary + 50000 from advisor where (select count(*) from advisor where i_id=id group by i_id)>1; 4. Set the credits to 2 for all courses which have less than 5 students taking them (across all sections for the course, across all years/semesters). Ans: update course set credits = 2 from (select cc, count(*) from (select course.course_id as cc from course left outer join takes on course.course_id = takes.course_id) as mm group by mm.cc) C where course.course_id=C.cc and C.count < 5;

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF