从 group by 子句 postgresql 过滤行

Filter rows from group by clause postgresql

我有以下 table,现在我想要 group by on col_1,并且想要 select 具有 col_2='ValueNet' and col_3='no' 的组的数据,并且还想排除满足在说条件之前。 (即 col_2='ValueNet' 和 col_3='no')

col_1  | col_2     |   col_3 <br>
1     | Community1 |  ACSNET    
1     | Community2 |  ACSNET    
1     | ValueNet   |  yes   
2     | Community3 |  ACSNET    
2     | Community4 |  ACSNET    
2     | ValueNet   |  no     

我的结果table应该是:

col_1    | col_2    |   col_3 <br>
2     | Community3 |  ACSNET    
2     | Community4 |  ACSNET    

一个选项是根据您提到的条件从 table 中找到所有结果的查询:“col_2='ValueNet' 和 col_3= 'no'",然后为要排除的内容创建一个例外子句:

select * from [Table_1] where col_1 in
(select col_1 from [Table_1] 
where col_2 ='ValueNet' and col_3='no')
except
(select * from [Table_1] 
 where col_2 ='ValueNet' and col_3='no')