Select '是在同一部门' where exists
(Select Dept_ID from 表 where staff_Name = '员工乙' and Dept_ID in (Select Dept_ID from 表 where staff_Name = '员工甲') )

解决方案 »

  1.   

    Select Dept_ID from 表 where staff_Name = '员工乙' and Dept_ID in (Select Dept_ID from 表 where staff_Name = '员工甲') 
      

  2.   

    if exists (select 1 from 表 a,表 b where a.Staff_Name='员工甲' and b.Staff_Name='员工乙' and a.Dept_ID=b.Dept_ID)
      select '在'
      

  3.   

    Select Dept_ID from 表 where staff_Name = '员工甲' and Dept_ID in (Select Dept_ID from 表 where staff_Name = '员工乙')
      

  4.   

    select * from 表 where Staff_Name='员工甲' and dept_id in (select dept_id  from 表 where Staff_Name='员工乙')
      

  5.   

    select case when exists 
    (select 1 from [table] t ,[table ] t2
    where t.Staff_Name in ('员工甲','员工乙') and t2.Staff_Name in ('员工甲','员工乙') and t.dept_id=t2.dept_id and t.Staff_Name<>t2.Staff_Name ) then '在同一部门' else 
    '不在同一部门' end 
    今天怎么写得这么复杂?回去睡觉
      

  6.   

    select * from 表 where (select Dept_ID from 表 where staff_Name = '员工甲') as Dept_ID1 in (select Dept_ID from 表 where staff_Name = '员工乙') as Dept_ID2
      

  7.   

    select case a.dept_id when b.deptid then '同一部门' else '不同部门' end
    from(select dept_id from 表 where staff_name='员工甲') a left join(select dept_id from 表 where staff_name='员工乙') b on a.dept_id=b.dept_id
      

  8.   

    haha .用一个内连接不就可以了吗?为什么大家写的都这么难呢?