How can I count easily the number of rows where a particular column is true
and the number where it is false
?
I can't (or can I ?) run the query with count() because I'm embedding this count in a having() clause, like :
.having(func.count(Question.accepted) >
func.count(not_(Question.accepted)))
but with the above way, the function counts every line on both sides of the inequality.
I tried something like this
.having(func.count(func.if_(Question.accepted, 1, 0)) >
func.count(func.if_(Question.accepted, 0, 1)))
But I get an error
function if(boolean, integer, integer) does not exist
(seems it doesn't exist in postgresql).
How can I count easily the number of rows where column is true and false ?