如何过滤相同的值

时间:2017-02-20 14:05:26

标签: php mysql

我有2个表格( docs & doc_process ):

文档

id | content   | status
------------------------
1  | content 1 | 1
2  | content 2 | 2

doc_process

id | doc_id | user | status
---------------------------    
1  | 1      | 1    | 2
2  | 1      | 2    | 2
3  | 1      | 3    | 2
4  | 2      | 1    | 1
5  | 2      | 2    | 2
6  | 2      | 3    | 1

如果所有doc_id = 1的值均为2

,如何选择状态
doc_id | status
---------------    
1      | 2

doc_id 2未过滤,因为id = 4id = 6不等于2

1 个答案:

答案 0 :(得分:-1)

使用条件聚合

select doc_id
from your_table
group by doc_id
having sum(status <> 2) = 0