以下条件的SQL查询

时间:2016-10-14 12:26:16

标签: mysql sql select

Employee_id    Status 
-----------------------
111            Approved
111            Approved
111            Pending
222            Approved
222            Approved

在我的表中,如上所述,只有222应该获得批准的解决方案。

我尝试过的事情:

select distinct employee_id, status
from main_table 

3 个答案:

答案 0 :(得分:1)

如果我理解正确,您正在寻找除“已批准”之外没有任何状态的员工。这可以表示为sed -i "s/ERROR/NOTE/g" $log_file; 条件:

not exists

答案 1 :(得分:0)

试试这个:

SELECT DISTINCT employee_id
FROM main_table
WHERE employee_id NOT IN (SELECT s.employee_id FROM main_table as s
                          WHERE Status != 'Approved')

答案 2 :(得分:0)

SELECT employee_id
  FROM main_table a
 GROUP BY employee_id
HAVING sum( case status when 'Approved' then 0 else 1 end ) = 0