Ask Search:
Timothy SmithTimothy Smith 

SOQL for trigger using Last_N_days

Goal:  Find Accounts that have opened 8 or more cases in the last 5 days.
My SOQL query is : 

Select AccountId,Count(Id) co from case where CreatedDate = LAST_N_DAYS:5 Group by AccountId

I don't see how to add in the condition of 8 or more cases. 
Best Answer chosen by Timothy Smith
Deepak AnandDeepak Anand
By using the HAVING clause like this = 
SELECT AccountId, COUNT(Id)
FROM Case
WHERE CreatedDate = LAST_N_DAYS:5
GROUP BY AccountId
HAVING COUNT(Id) >=8
Ref: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_having.htm