Академический Документы
Профессиональный Документы
Культура Документы
where emp_id in
(select superior_emp_id
from employee
where assigned_branch_id in
(select branch_id
from branch
where state like 'NH'));
--7.Which departments had employees start in 2002?
select name
from department
where dept_id in
(select dept_id
from employee
where start_date between '01-01-2002' and '31-12-2002');
--8.List accounts opened by customers from Salem at the branch in the same city.
select account_id
from account
where cust_id in
(select cust_id
from customer
where city like 'Salem'
and
open_branch_id in
(select branch_id
from branch
where city like 'Salem'));
--B Queries in this section are excerpted from the Subqueries 2 Note (SQL 4.2).
--Try them out, then visit the note where you are guided to some of the solution
s.
-- 1.which employee directly reports to the president, but manages no one?
select fname, lname
from employee
where emp_id not in
(select superior_emp_id
from employee
where superior_emp_id is not null)
and
superior_emp_id =
(select emp_id
from employee
where title like 'President');
/* 2. all accounts opened by Tellers at Woburn Branch */
select account_id
from account
where open_branch_id in
(select branch_id
from branch
where name like 'Woburn Branch')
and open_emp_id in
(select emp_id
from employee
where title like 'Teller' or title like 'Head Teller');
from customer
where city in ('Salem', 'Quincy', 'Woburn'));
--6. Show Tellers managed by Head Tellers
select fname, lname, emp_id
from employee
where title like 'Teller'
and
superior_emp_id in
(select emp_id
from employee
where title like 'Head Teller');
--7. Show department names for all Teller managed by the Head Teller
select name
from department
where dept_id in
(select dept_id
from employee
where title like 'Teller'
and
superior_emp_id in
(select emp_id
from employee
where title like 'Head Teller'));