Monday, January 27, 2014

How to write the “Where” clause in SOQL when GroupBy is used for aggregate functions

How to write the “Where” clause in SOQL when GroupBy is used for aggregate functions

We cannot use the “Where” clause with GroupBy for aggregate functions like SUM() instead we will need to use the “Having Clause“.
Example : Get all the opportunity where more than one record exists with same name and name contains “ABC”.
SELECT COUNT(Id) , Name FROM Opportunity GROUP BY Name  Having COUNT(Id) > 1 AND Name like '%ABC%'
Read more about Having clause


No comments:

Post a Comment