Select users belonging only to particular departments

后端 未结 12 2245
挽巷
挽巷 2021-02-18 12:49

I have the following table with two fields namely a and b as shown below:

create table employe
(
    empID varchar(10),
    department varchar(10)
);
         


        
12条回答
  •  野的像风
    2021-02-18 13:46

    For condition 1:z and y

     select z.empID from (select empID from employe where department = 'z' ) as z
    inner join (select empID from employe where department = 'y' )  as y 
    on z.empID = y.empID
    where z.empID Not in(select empID from employe where department = 'x' ) 
    

    For condition 1:z and x

    select z.empID from (select empID from employe where department = 'z' ) as z
    inner join (select empID from employe where department = 'x' )  as x 
    on z.empID = x.empID
    where z.empID Not in(select empID from employe where department = 'y' )
    

    For condition 1:z,y and x

    select z.empID from (select empID from employe where department = 'z' ) as z
    inner join (select empID from employe where department = 'x' )  as x 
    on z.empID = x.empID
    inner join (select empID from employe where department = 'y' )  as y on 
    y.empID=Z.empID
    

提交回复
热议问题