diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 4fc9bd6f213c..b4c5951fb6e2 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -4703,11 +4703,11 @@ public static function appendAnyValueToSelect($selectClauses, $groupBy) { * */ public static function getGroupByFromOrderBy(&$groupBy, $orderBys) { - if (!CRM_Utils_SQL::disableFullGroupByMode()) { + if (CRM_Utils_SQL::disableFullGroupByMode()) { foreach ($orderBys as $orderBy) { $orderBy = str_replace(array(' DESC', ' ASC'), '', $orderBy); // remove sort syntax from ORDER BY clauses if present // if ORDER BY column is not present in GROUP BY then append it to end - if (!strstr($groupBy, $orderBy)) { + if (preg_match('/(MAX|MIN)\(/i', trim($orderBy)) !== 1 && !strstr($groupBy, $orderBy)) { $groupBy .= ", {$orderBy}"; } } diff --git a/CRM/Report/Form/Mailing/Summary.php b/CRM/Report/Form/Mailing/Summary.php index 75f2b9617478..3d41981a6e80 100644 --- a/CRM/Report/Form/Mailing/Summary.php +++ b/CRM/Report/Form/Mailing/Summary.php @@ -149,11 +149,13 @@ public function __construct() { 'order_bys' => array( 'start_date' => array( 'title' => ts('Start Date'), + 'dbAlias' => 'MAX(mailing_job_civireport.start_date)', ), 'end_date' => array( 'title' => ts('End Date'), 'default_weight' => '1', 'default_order' => 'DESC', + 'dbAlias' => 'MAX(mailing_job_civireport.end_date)', ), ), 'grouping' => 'mailing-fields',