2015-07-10 31 views
2

我有一個表(有大約100萬行)如下PostgreSQL的查詢無匹配標準

identifier  bigint 
active   boolean 
extraInformation character varying(100) 

的數據可以和將有幾行,其中活躍的是假的每一個標識,但必須始終準確每個標識符都有一個激活狀態。

有一個錯誤,導致某些標識符的所有活動標誌設置爲false。

因此,我需要一個查詢,如下所示:

顯示有設置爲false

+0

是標識符和活動的列名?你可以使用我認爲的 – joncodo

回答

5

如果你是9.4所有的有效標誌所有的標識符,您可以使用此:

select identifier 
from the_table 
group by identifier 
having count(*) = count(*) filter (where not active); 

對於舊版本:

select identifier 
from the_table 
group by identifier 
having count(*) = count(case when not active then 1 end); 

SQLFiddle:http://sqlfiddle.com/#!15/7423e/2

+0

比我的建議更好,我會刪除我的答案 – Lennart

+0

@a_horse_with_no_name:很好的答案。謝謝。 – Ask613