Chapter 03 Part4 Database 3CS
Chapter 03 Part4 Database 3CS
Level #3
Chapter #3
Part #4
Database
2020
Q1. What is Nested Subqueries?
Is a select-from-where expression that is nested within another query.
1 DataBase 2020
3) Find the total number of (distinct) students who have taken course sections taught
by the instructor with ID 10101
Select count (distinct ID )
from takes
where (course_id, sec_id , semester , year ) in (select course_id , sec_id ,
semester , year
from teaches
where teaches .ID = 10101 );
4) Find names of instructors with salary greater than that of some (at least one)
instructor in the Biology department.
Select distinct T.name
from instructor as T, instructor as S
where T.salary> S.salary and S.dept_name = 'Biology';
Other Resolution
Select name
from instructor
where salary > some(select salary
from instructor
where dept_name = 'Biology');
5) Find the names of all instructors whose salary is greater than the salary of all
instructors in the Biology department.
Select name
from instructor
where salary > all (select salary
from instructor
where dept_name= 'Biology');
6) True Or False:
2 DataBase 2020
7) Delete all instructors from the Finance department
Delete from instructor where dept_name= 'Finance';
8) Delete all tuples in the instructor relation for those instructors associated with a
department located in the Watson building.
Delete from instructor
Insert into course (course_id , title , dept_name ,credits )values ('CS -437',
11) Add all instructors to the student relation with tot_creds set to 0
Insert into student select ID, name, dept_name, 0 from instructor
12) Increase salaries of instructors whose salary is over $100,000 by 3%, and all
others receive a 5% raise
Soluion1: Write two update statements:
Update instructor set salary = salary * 1.03
else salary*1.03
end
3 DataBase 2020