PostgreSQL查询无匹配条件

Ask*_*613 2 sql postgresql

我有一张桌子(大约有1亿行)如下

identifier       bigint
active           boolean
extraInformation character varying(100)
Run Code Online (Sandbox Code Playgroud)

对于每个标识符,数据可以并且将具有多行,其中active为false,但是对于每个标识符,必须始终只有一个active为true的行.

有一个错误导致某些标识符的所有活动标志都设置为false.

因此,我需要一个查询如下:

显示所有活动标志设置为false的所有标识符

a_h*_*ame 5

如果你在9.4,你可以使用这个:

select identifier 
from the_table
group by identifier
having count(*) = count(*) filter (where not active);
Run Code Online (Sandbox Code Playgroud)

对于旧版本:

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

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