select * from employee a
where exists(select 1 from employee where empid = '1001' and depid = a.depid)

解决方案 »

  1.   

    select * from employee where depid=(select depid from employee where empid=1001);
      

  2.   

    select *
    from employee
    where depid=(select edepid
                 from employee
                 where empid=1001);
      

  3.   

    select * from Employee where depid in(
    select depid from Employee where EMPID='1001')
      

  4.   

    select * from Employee a where depid in(
    select depid from Employee where EMPID='1001') 
    and not exist( select * from employee where empid='10001' and depid not in (select depid from employee b where b.empid=a.empid))
      

  5.   

    select a.* from Employee a,(select * from employee where EmpID = '1001') b where 
    a.depid = b.depid;
      

  6.   

    sun1976:小弟有一事请教。
    你的语句中
    and not exist( select * from employee where empid='10001' and depid not in (select depid from employee b where b.empid=a.empid))
    看不太懂,这句话是什么意思?
      

  7.   

    没仔细想,可能语句有错误,好就没用oracle了,可能第二层子查询不能引用最表层的数据,也许要在第一层子查询加计算列才行
    我的意思是:如果一个员工可以对应多个部门,得到的员工的部门必须是包含在‘1001’员工的部门中的,而且‘1001’员工的所有部门也必须都包含于查询得到的员工的部门中,这样才能保证查询得到的员工和1001有完全相同的部门
    另外应该加上员工号<>'1001'