Fix count_rows with more than one group by column

This commit is contained in:
Jakub Vrana 2018-02-01 20:45:49 +01:00
parent 685bf29abc
commit 09920e0056

View file

@ -1292,7 +1292,7 @@ function count_rows($table, $where, $is_group, $group) {
$query = " FROM " . table($table) . ($where ? " WHERE " . implode(" AND ", $where) : "");
return ($is_group && ($jush == "sql" || count($group) == 1)
? "SELECT COUNT(DISTINCT " . implode(", ", $group) . ")$query"
: "SELECT COUNT(*)" . ($is_group ? " FROM (SELECT 1$query$group_by) x" : $query)
: "SELECT COUNT(*)" . ($is_group ? " FROM (SELECT 1$query GROUP BY " . implode(", ", $group) . ") x" : $query)
);
}