Fix queries to work with sql_mode=only_full_group_by

This commit is contained in:
Hypolite Petovan 2019-05-12 14:00:44 -04:00
parent 942de39e6d
commit a0cfd33521
6 changed files with 17 additions and 8 deletions

View File

@ -49,7 +49,7 @@ class Statistics extends BaseController
AND `available`
AND NOT `hidden`
GROUP BY `language`
ORDER BY COUNT(*) DESC';
ORDER BY `total` DESC';
$profileLanguages = $this->connection->fetchAll($stmt, ['total' => $profileCounts['language']]);
@ -88,7 +88,7 @@ class Statistics extends BaseController
AND `available`
AND NOT `hidden`
GROUP BY LEFT(`language`, 2)
ORDER BY COUNT(*) DESC';
ORDER BY `total` DESC';
$serverLanguages = $this->connection->fetchAll($stmt, ['total' => $serverCounts['language']]);
@ -98,7 +98,7 @@ class Statistics extends BaseController
AND `available`
AND NOT `hidden`
GROUP BY `version`
ORDER BY COUNT(*) DESC';
ORDER BY `total` DESC';
$serverVersions = $this->connection->fetchAll($stmt, ['total' => $serverCounts['version']]);

View File

@ -93,7 +93,7 @@ class Profile extends \Friendica\Directory\Model
WHERE p.`available`
AND NOT p.`hidden`
' . $condition . '
GROUP BY p.`id`
GROUP BY p.`id`, `filled_fields`, `last_activity`, `updated`
ORDER BY `filled_fields` DESC, `last_activity` DESC, `updated` DESC
LIMIT :start, :limit';
$profiles = $this->atlas->fetchAll($stmt, $values);

View File

@ -40,7 +40,7 @@ class AccountTypeTabs
AND NOT p.`hidden`
' . $condition . '
GROUP BY p.`account_type`
ORDER BY `filled_fields` DESC, `last_activity` DESC, `updated` DESC';
ORDER BY `count` DESC';
$account_types = $this->connection->fetchAll($stmt, $values);
$tabs = [

View File

@ -30,7 +30,7 @@ FROM `profile`
WHERE `country` != ""
AND `available`
GROUP BY `country`
ORDER BY COUNT(`country`) DESC
ORDER BY `total` DESC
LIMIT 10';
$countries = $this->connection->fetchAll($stmt);

View File

@ -24,7 +24,12 @@ class PopularLanguages
public function render(): string
{
$stmt = 'SELECT LEFT(`language`, 2) AS `language`, COUNT(*) AS `total` FROM `profile` WHERE `language` IS NOT NULL GROUP BY LEFT(`language`, 2) ORDER BY COUNT(*) DESC LIMIT 10';
$stmt = 'SELECT LEFT(`language`, 2) AS `language`, COUNT(*) AS `total`
FROM `profile`
WHERE `language` IS NOT NULL
GROUP BY LEFT(`language`, 2)
ORDER BY `total` DESC
LIMIT 10';
$languages = $this->connection->fetchAll($stmt);
$vars = [

View File

@ -24,7 +24,11 @@ class PopularTags
public function render(): string
{
$stmt = 'SELECT `term`, COUNT(*) AS `total` FROM `tag` GROUP BY `term` ORDER BY COUNT(`term`) DESC LIMIT 10';
$stmt = 'SELECT `term`, COUNT(*) AS `total`
FROM `tag`
GROUP BY `term`
ORDER BY `total` DESC
LIMIT 10';
$tags = $this->connection->fetchAll($stmt);
$vars = [