+ Start a Discussion
kkr.devkkr.dev 

Sorting aggregate results ..Urgent

Hi All,

 

       I need to know is it possible to sort aggregate results in sorting?

 

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
ChizChiz
List<AggregateResult> aggSummary =
[
 SELECT sum(x1__c) xx1, x2__c xx2, x2__r.Name xx2Name, x2__r.x2_x__c x2x
 FROM qq__c qq
 GROUP BY x2__r.Name, x2__r.x2_x__c, x2__c
 ORDER BY sum(x1__c)
];

 Yes. But put sum(xx1) instead of simple "xx1".

All Answers

ChizChiz
List<AggregateResult> aggSummary =
[
 SELECT sum(x1__c) xx1, x2__c xx2, x2__r.Name xx2Name, x2__r.x2_x__c x2x
 FROM qq__c qq
 GROUP BY x2__r.Name, x2__r.x2_x__c, x2__c
 ORDER BY x2__c
];

 

 This query works perfect. If you was askign for ORDER BY.

kkr.devkkr.dev
List<AggregateResult> aggSummary =
[
 SELECT sum(x1__c) xx1, x2__c xx2, x2__r.Name xx2Name, x2__r.x2_x__c x2x
 FROM qq__c qq
 GROUP BY x2__r.Name, x2__r.x2_x__c, x2__c
 ORDER BY xx1
];

Thanks for your reply ..I need Order by XX1. Is this possible ?

ChizChiz
List<AggregateResult> aggSummary =
[
 SELECT sum(x1__c) xx1, x2__c xx2, x2__r.Name xx2Name, x2__r.x2_x__c x2x
 FROM qq__c qq
 GROUP BY x2__r.Name, x2__r.x2_x__c, x2__c
 ORDER BY sum(x1__c)
];

 Yes. But put sum(xx1) instead of simple "xx1".

This was selected as the best answer
kkr.devkkr.dev

Thanks a lot.I appreciate it.