liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public with sharing class LexConsumableAccountSOQL {
    public static AggregateResult[] getAccountBySales(Datetime thisDatetime ,Datetime nextDatetime){
        AggregateResult[] arList = new List<AggregateResult>([
            SELECT Consumable_order__r.Order_ForHospital__c,Consumable_order__r.Order_ForHospital__r.name hospitalName,
            sum(Sale_amount__c) thisAmount
            FROM Consumable_Orderdetails__c
            WHERE
                CreatedDate >= :thisDatetime
                AND CreatedDate < :nextDatetime
                AND Consumable_order__r.Order_ForHospital__r.name != ''
            GROUP BY Consumable_order__r.Order_ForHospital__c,Consumable_order__r.Order_ForHospital__r.name
            ORDER BY sum(Sale_amount__c) DESC
            LIMIT 10
        ]);
        return arList;
    }
 
    public static AggregateResult[] getAccountTotalSales(Datetime thisDatetime ,Datetime nextDatetime){
        AggregateResult[] saleAmountList = [
            SELECT sum(Sale_amount__c) saleAmount
            FROM Consumable_Orderdetails__c
            WHERE CreatedDate >= :thisDatetime 
            AND CreatedDate < :nextDatetime 
            AND Consumable_order__r.Order_ForHospital__r.name != ''
        ];
        return saleAmountList;
    }
 
  
}