Cycle 1
Cycle 1
Cycle - 1
Problem 1
Consider the following database schema:
attributes:
Employee table.
II. Write SQL queries for retrieving data from multiple tables using Joins:
1. Find all possible combinations of instructors and the courses they teach.
2. Retrieve the names of all instructors, along with their department names and
department building name.
3. Find the names of instructors who have taught at least one course.
4. For the student with ID 12345 (or any other value), show all course_id and title of
all courses registered for by the student.
5. Find instructor names and course identifiers for instructors in the Computer
Science department.
6. For all instructors in the university who have taught some course, find their
names and the course ID of all courses they taught.
7. Find the names of all instructors whose salary is greater than at least one
instructor in the Biology department. Or Find the names of all instructors who earn
more than the lowest paid instructor in the Biology department.
8. Find full details of instructors who teach at least one course.
9. Find the instructor names and the courses they taught for all instructors in the
Biology department who have taught some course.
10. Find the set of all courses taught either in Fall 2009 or in Spring 2010, or both.
11. Find all courses taught in the Fall 2009 semester but not in the Spring 2010
semester.
12. Find the names of all students who have taken any Comp. Sci. course ever. (there
should be no duplicate names)
13. Display the IDs of all instructors who have never taught a course. (Don’t write
nested query)
Problem 4
I Write SQL Select Statements using Aggregate Functions, Group By and Having
clauses for the following queries that retrieve data from university database:
1. Find the maximum and average capacity of buildings in the university.
2. Display the least budget of the departments.
3. Find the total number of courses and credits offered by Biology
department.
4. Find the average salary of instructors in the Computer Science
department.
5. Find the total number of instructors who teach a course in the Spring
2010 semester.
6. Find the average salary in each department.
7. Find the number of instructors in each department who teach a course in
the Spring 2010 semester.
8. Find the department name and average salary of the department for only
those departments where the average salary of the instructors is more
than $42,000.
9. For each course section offered in 2009, find the average total credits
(tot_cred) of all students enrolled in the section, if the section had at least
2 students.
10. For each department, find the maximum salary of instructors in that
department. You may assume that every department has at least one
instructor.
11. For the student with ID 12345 (or any other value), show the total
number of credits scored for all courses (taken by that student). Don't
display the tot_creds value from the student table, you should use SQL
aggregation on courses taken by the student.
12. Display the total credits for each of the students, along with the ID of the
student; don't bother about the name of the student. (Don't display the
tot_creds value from the student table, you should use SQL aggregation on
courses taken by the student. For students who have not registered for
any course, tot_creds should be 0)
II Write nested queries for answering the following queries that retrieve data from
university database:
1. Find the total number of (distinct) students who have taken course
sections taught by the instructor with ID 110011
2. Find the names of all instructors whose salary is greater than at least one
instructor in the Biology department
3. Find the departments that have the highest average salary.
4. Find all the courses taught in the both the Fall 2009 and Spring 2010
semesters
5. Find all the courses taught in the Fall 2009 semester but not in the Spring
2010 semester.
6. Find all courses taught in both the Fall 2009 semester and in the Spring
2010 semester. (Write correlated nested Query)
7. Find all students who have taken all courses offered in the Biology
department. (Write Correlated nested Query)
8. Find all courses that were offered at most once in 2009.
9. Find all courses that were offered at least twice in 2009”
10. Find the average instructors’ salaries of those departments where the
average salary is greater than $42,000.
11. Find the departments with the maximum budget.
12. Find the names of instructors who have not taught any course.
13. Find the IDs and names of all students who have not taken any course
offering before Spring 2009.
14. Find the lowest, across all departments, of the per-department maximum
salary computed.
15. Display the IDs and names of the instructors who have taught all Comp.
Sci. courses.