Professional Documents
Culture Documents
Computer Engineering: Database Systems (DS) Assignment
Computer Engineering: Database Systems (DS) Assignment
Name:-Nishant Sharma
Roll No.:-11912090
Section:-CS-B(6)
EXPERIMENT Number=7
#Write the following queries in the SQL using set operations union, intersect, except, etc.
(for the above mentioned database of a university)
1.Find courses taught in Fall 2015 or in Spring 2016. (use union operation)
I have used Fall 2015 as 1 and Spring 2016 as 2.
mysql> select c.course_id,title
-> from section s,course c
-> where c.course_id=s.course_id and year=1
-> union
-> select c.course_id,title
-> from section s,course c
-> where c.course_id=s.course_id and year=2;
2.Find courses taught in Fall 2015 and in Spring 2016. (use intersect operation)
I have used Fall 2015 as 1 and Spring 2016 as 2.
mysql> select distinct c.course_id,title
-> from section s,course c
-> where c.course_id=s.course_id and year=1 and c.course_id in(select distinct c.course_id
-> from course c,section s
-> where c.course_id=s.course_id and year=2);
3.Find courses taught in Fall 2015 but not in Spring 2016. (use except operation)
I have used Fall 2015 as 1 and Spring 2016 as 2.
5.Find courses taught/offered by Computer Engg. department in Fall 2015 and ECE
department in Spring 2016. (use intersect operation)
I have used Fall 2015 as 1 and Spring 2016 as 2.
6.Find courses taught/offered by Computer Engg. department in Fall 2015 but not by ECE
department in Spring 2016. (use except operation)
I have used Fall 2015 as 1 and Spring 2016 as 2.
Making use of sub-queries and "in", "not in" connectives, write queries for the following:
9.Find courses taught in Fall 2015 and in Spring 2016. (sub-query, in)
I have used Fall 2015 as 1 and Spring 2016 as 2.
10.Find courses taught in Fall 2015 but not in Spring 2016. (sub-query, not in)
I have used Fall 2015 as 1 and Spring 2016 as 2.
12.Find courses taught/offered by Computer Engg. department in Fall 2015 but not by ECE
department in Spring 2016. (sub-query, not in)
I have used Fall 2015 as 1 and Spring 2016 as 2.
13.Find total no. of distinct students who have taken courses taught in different sections by
an instructor. (Take a valid instructor ID or name)
Based on the observations of the result, write the query in English language. Give your
opinion on any different version of the above query.
mysql> select name as 'name of instructors whose salaries are greater than salaries of all the instuctors of physics
department'
-> from instructor
-> where salary>all(select salary
-> from instructor
-> where dept_name='physics');
"Find department names along with average salaries of the instructors of that department
where average salaries are greater than Rs. 45000"
"Retrieve name of department along with no. of students who have earned total credits
more than 7"
21.List instructor name, dept name, and no. of courses taught by the instructor in Spring
2016.
I have used Spring 2016 as 2.
THANK YOU