--- plugins/views_plugin_query_default.inc.orig	2011-10-26 16:21:36.000000000 -0400
+++ plugins/views_plugin_query_default.inc	2011-10-26 16:21:54.000000000 -0400
@@ -1014,25 +1014,25 @@ class views_plugin_query_default extends
     $joins = $where = $having = $orderby = $groupby = '';
     // Add all the tables to the query via joins. We assume all LEFT joins.
     foreach ($this->table_queue as $table) {
       if (is_object($table['join'])) {
         $joins .= $table['join']->join($table, $this) . "\n";
       }
     }
 
     list($distinct, $fields, $non_aggregates) = $this->compile_fields($fields_array);
 
-    if (count($this->having)) {
+    if (count($this->having) || count($this->groupby)) {
       $this->has_aggregate = TRUE;
     }
     if ($this->has_aggregate && (!empty($this->groupby) || !empty($non_aggregates))) {
-      $groupby = "GROUP BY " . implode(', ', array_unique(array_merge($this->groupby, $non_aggregates))) . "\n";
+      $groupby = "GROUP BY " . implode(', ', array_diff($this->groupby, $non_aggregates)) . "\n";
       if ($this->having) {
         $having = $this->condition_sql('having');
       }
     }
 
     if (!$get_count_optimized) {
       // We only add the orderby if we're not counting, because of performance reasons.
       if ($this->orderby) {
         $orderby = "ORDER BY " . implode(', ', $this->orderby) . "\n";
       }
