public function applyAggregate(DataQuery $query, $having)
    {
        $schema = DataObject::getSchema();
        $baseTable = $schema->baseDataTable($query->dataClass());

        return $query
            ->having($having)
            ->groupby("\"{$baseTable}\".\"ID\"");
    }