Select users belonging only to particular departments

后端 未结 12 2290
挽巷
挽巷 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条回答
  •  梦毁少年i
    2021-02-18 13:48

    Try this,

    SELECT  a.empId
    FROM    employe a
            INNER JOIN
            (
                SELECT  empId
                FROM    employe 
                WHERE   department IN ('X', 'Y', 'Z')
                GROUP   BY empId
                HAVING  COUNT(*) = 3
               )b ON a.empId = b.empId
    GROUP BY a.empId
    

    Count must based on number of conditions.

提交回复
热议问题