Dave J did a tonne of work fixing up this report & adding a unit test - this complete by just handling FGB very specifically
on one query
// store the result in temporary table
$insertQuery = "INSERT INTO {$this->_tempDurationSumTableName} (civicrm_activity_duration_total)
{$sql}";
+ CRM_Core_DAO::disableFullGroupByMode();
CRM_Core_DAO::executeQuery($insertQuery);
+ CRM_Core_DAO::reenableFullGroupByMode();
$sql = "SELECT {$this->_tempTableName}.*, {$this->_tempDurationSumTableName}.civicrm_activity_duration_total
FROM {$this->_tempTableName} INNER JOIN {$this->_tempDurationSumTableName}