global class SumEquipmentInventory implements Database.Batchable<sObject> {
    public String query;

    global SumEquipmentInventory() {
        this.query = query;
    }

    global Database.QueryLocator start(Database.BatchableContext bc) {
        query = 'select Hospital__c , COUNT(Id)conData from Asset where Status =\'使用中\' group by Hospital__c';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, list<AggregateResult> assList) {
        // Map<Account_Service_Of_Target__c,Integer> count = new Map<Account_Service_Of_Target__c,Integer>();
        List<Account_Service_Of_Target__c> asList = new List<Account_Service_Of_Target__c>();
        for (AggregateResult ass : assList ) {
            Account_Service_Of_Target__c asItem = new Account_Service_Of_Target__c();
            asItem.Account_HP__c = (Id)ass.get('Hospital__c');
            asItem.Equipment_Inventory_No__c = (Decimal)ass.get('conData');
            asList.add(asItem);
        }
        upsert asList;
    }

    global void finish(Database.BatchableContext BC) {

    }
}