select employee_name from employee where
exists (select 1 from employee e, manages m where e.street+e.city=employee.street+employee.city
and m.employee_name=w2.employee_name)
如果需要显示是经理或者员工就变成
select employee_name,works.street,works.city,
(case when manages.manager_name is not null then manages.manager_name
else 'IS WORKER 'end ) as State
from employee,manages ,works
where
exists (select 1 from employee e, manages m where e.street+e.city=employee.street+employee.city
and m.employee_name=w2.employee_name)
and employee.employee_name *= manages.employee_name
and employee.employee_name *= works.employee_name
order by city,State
或者
select employee_name from employee where
exists (select 1 from employee e, manages m where e.street+e.city=employee.street+employee.city
and m.employee_name=w2.employee_name)
想错了,应该是:
select employee_name from employee where (select count(*) from employee e where e.street+e.city=employee.street+employee.city)
>(select count(*) from employee e, works w2 where e.street+e.city=employee.street+employee.city and e=w2.employee_name)
select *
,(select manager_name
from manages
where employee_name = a.employee_name
)
from employee a
where employee_name in (select employee_name
from manages
where manager_name in (select employee_name
from employee
where city = a.city
and street = a.street
)
)
select employee_name from employee where (select count(*) from employee e where e.street+e.city=employee.street+employee.city)
>(select count(*) from works w2 where w2.employee_name=employee.employee_name)
可以求出名字,剩下的就简单了
如果不是