Ross Dargan
Ross Dargan

Reputation: 6021

Counting how many records are true

I'd like to do a query like this:

select count(c.id) as count, sum(c.boolProperty) as sum from c

with data like this: { "id":"1","boolProperty":true} { "id":"2","boolProperty":false}

to return

{ "count": 2, "sum": 1 }

I suspect I will need to do two queries, but wanted to check

Upvotes: 0

Views: 751

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222532

No you cannot do this since your boolproperty is a boolean so it cannot do a aggregation over it.

Instead you can use where clause , but in this case it will be applied to count as well

SELECT COUNT(C.id) as count,  COUNT(C.id) as sum  FROM C where C.boolProperty = true

Upvotes: 1

Related Questions