soql – Combining where and having clauses in group by
I am running a group by query. As part of this, I want to check the sum of one field, and then check if that sum exceeds a number. The number itself depends on the value of a second field, which is a picklist field. I can do this by using multiple queries, but I am trying to see if it can be done in one query. Essentially, I want to be able to do something like this, which is not currently available in SOQL.
select fielda__c,sum(fieldb__c) from obja__c where
(fieldc__c="Value A" and having sum(fieldb__c) > 10) or
(fieldc__c="Value B" and having sum(fieldb__c) > 20) or
(fieldc__c="Value C" and having sum(fieldb__c) > 30) or
group by fielda__c
Is this possible, or is my only option to use multiple queries?
Read more here: Source link
