function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Luke Higgins 23Luke Higgins 23 

Help building SOQL nested query with a COUNT()

I am trying to return placements that occur in the query more than once and I am getting the error "Only root queries support aggregate expressions." Is there another way to count the placements than using a nested query? I know that GROUP BY is not supported in the sub-query but I'm unsure how else to go about it.

Here is what I have so far:
SELECT jstcl__Placement__r.Name,
(SELECT COUNT(Name) FROM Placements__r Group By Id COUNT(NAME) > 1)
FROM jstcl__TG_Timesheet__c WHERE jstcl__Placement__r.ts2__Status__c IN ('Active') AND jstcl__Week_Ending__c = LAST_N_DAYS:14 AND jstcl__Status__c = 'Pending'

 
MagulanDuraipandianMagulanDuraipandian
Try like below. I have used Account and Contact.

Sample SOQL - http://www.infallibletechie.com/2018/04/how-to-count-child-records-for-each.html