0

Trying to use an aggregate query to count certain records. Now I know that Number type fields cannot be used in Group By so I'm trying the following:

SELECT Count(Id), Max(Number_Field__c) FROM MyObject__c GROUP BY Text_Field__c HAVING Text_Field__c = 'String Literal' AND Number_Field__c >= 1000000  

But I'm still getting an error [object Object]: HAVING expression must be grouped or aggregated from the Query Editor.

2
  • Your query looks like you want to use WHERE instead of HAVING. What exactly are you trying to do?
    – sfdcfox
    Dec 15 '20 at 9:32
  • We want an aggregate result counting the number of records fulfilling both conditions Dec 15 '20 at 9:42
0

You should include the text field in your field list. Also, having is used to find a group of records that meet some criteria (for example, multiple records that have the same name). It looks like you want a WHERE clause instead.

SELECT Count(Id), Text_Field__c, Max(Number_Field__c) 
FROM MyObject__c 
WHERE Text_Field__c = 'String Literal' AND Number_Field__c >= 1000000 
GROUP BY Text_Field__c  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.