php - mysql升级到8后报错,only_full_group_by错误

标签 php mysql group-by mysql-error-1055

这一行给了我错误:

Error: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'hng_1.tags.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

foreach($groups as $group)
    {
            $query = mysqli_query($verbindung, "SELECT * FROM (SELECT *, COUNT(id) AS c FROM tags WHERE typ='" . mysqli_real_escape_string($verbindung, $group) . "' GROUP BY slug ORDER BY c DESC LIMIT 9) AS i ORDER BY i.tag ASC") or die("Error: " . mysqli_error($verbindung));

            while ($row = mysqli_fetch_array($query)) {
                    $tmp_tags[] = $row;
            }
    }

如何更改查询来修复此错误?

最佳答案

对于其他感兴趣的人,我解决了这个问题。我将 id 添加到 GROUP BY,因此它现在知道要选择什么。

GROUP BY slug, id 

修复它。

关于php - mysql升级到8后报错,only_full_group_by错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51465991/

相关文章:

mysql - SQL Like %>=值

python - 如何在 Pandas 的所有适用行中复制 groupby 的平均值

mysql - 如何对重复的对进行分组并对它们编写查询?

python - 在 Pandas 中分组

PHP - 改进随机数序列生成

php - preg_match - 只能由数字、连字符 (-) 和空格组成

python - Django 中数据库的下载链接

java - Eclipse for PHP 和 Eclipse 或 Java 互相搞乱了?

php - 奇怪的 PHP 行为,基类和派生类的字段名称相同,克隆实例

mysql - 将facebook数据存储到mysql