Reputation: 702
I have the following query:
select count(*)
from "my_table"
where field1 = true and field2 = 'delivered'
group by grouping sets((field3), (field4), (field5))
having field3 = true or field4 = true or field5
For each group in the grouping set, I want to get the count of the true values. The problem with this query however is that it has no labels attach to it. In case there are no results for a group, the group is excluded in the end result. Is it possible to include groups with count 0 or create a set of labels so that it becomes clear to which group the count corresponds in the result?
Current result:
count
_____
1
2
Where field5 doesn't have any results so it isn't included.
Desired result:
count
-----
1
2
0
Or:
count_field3 | count_field4 | count_field5
------------------------------------------
1 | 2 | 0
Upvotes: 0
Views: 61