我用這個變化:返回COUNT每一行,而不是在POSTGRES
SELECT (select count(active) AS true
from sooper_entry
where active = 't'
and entry_id_ref = 28) AS true,
(select count(active) AS false
from sooper_entry
where active = 'f'
and entry_id_ref = 28) AS false;
所以我可以得到所有的真與假的計數,但我需要一個真正的假count在關聯數組中返回。
期望的結果:
true | false | uId
------+-------+-----
16 | 0 | 1
10 | 2 | 3
13 | 10 | 4
19 | 8 | 5
12 | 3 | 8
21 | 0 | 12
(6 rows)
完美和簡單!非常感謝,你做搖滾! (顯然我還不能給任何人+1,有人請爲我做!)我現在可以+1! – roberthuttinger
@robert:請將其中一個答案(您認爲最有幫助的)標記爲已接受。要做到這一點,請點擊答案的選票數下面的複選標記,以便它變成綠色。 – Quassnoi
從我這裏稍微加了一點:'SELECT SUM(active :: BOOLEAN :: INT)as active,SUM((NOT active :: BOOLEAN):: INT)as inactive,entry_id_ref FROM sooper_entry GROUP BY entry_id_ref' – roberthuttinger