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
ArjunmcaArjunmca 

Parent and child relationship query with aggregate values.



Hi,

I am writing a relationship query to getch multiple values in a single query.

'select contact.Account.ID,SUM(Contact.NoOfPagesPrinted__C) from contact where Contact.DatePrinted__c = LAST_N_DAYS:30 and Contact.Account.AccountType__c=:acType group by Contact.Account.ID'

The above query is working. But i want sum of pages  printed  for last 90 and 120 pages as well.
So i modified the query as below

'select contact.Account.ID,SUM(Select Contact.NoOfPagesPrinted__C from contact where Contact.DatePrinted__c = LAST_N_DAYS:30), sum( Select Contact.NoOfPagesPrinted__C from contact where Contact.DatePrinted__c = LAST_N_DAYS:90), sum( Select Contact.NoOfPagesPrinted__C from contact where Contact.DatePrinted__c = LAST_N_DAYS:120) from contact where Contact.Account.AccountType__c=:acType group by Contact.Account.ID'.

but its giving error. Can any body correct this query please.

Thanks.


ShaTShaT
HI,

You can refer below link it may help to understand the Aggregate funtions.
http://blog.jeffdouglas.com/2010/02/22/soql-how-i-query-with-thee-let-me-count-the-ways/

Thanks
Shailu