本网站主要是放置一些个人的家庭信息和学习资源,方便自己和家人的查询和学习,此外也放置了一些自己常用的网络视频方便自己和家人浏览。

电脑常识

当前位置:首页 > 电脑常识

进入内容页MySQL Error修复

进入内容页文章评论下方出现MySQL Error,

进入内容页文章评论下方出现MySQL Error,进入调试模式显示下方信息

Execute SQL error, message : SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'lys2011.lys_article.inputtime' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by


SELECT FROM_UNIXTIME(inputtime, '%Y年%m月') AS pubtime, count(*) AS total,inputtime FROM `lys2011` . `lys_article` WHERE `status`=1 GROUP BY FROM_UNIXTIME(inputtime, '%Y年%m月') ORDER BY pubtime DESC LIMIT 10

这个错误是由于 MySQL 的 only_full_group_by SQL 模式引起的。在这个模式下,SELECT 列表中的非聚合列必须出现在 GROUP BY 子句中,或者这些非聚合列必须是 GROUP BY 列的函数依赖项。当前 SQL 语句里,inputtime 是非聚合列,且不在 GROUP BY 子句中,所以会报错。

修改 GROUP BY 子句,把 inputtime 添加到 GROUP BY 子句中,不过这可能会改变查询结果,因为会按照 inputtime 的精确值分组。需要修改的文件的位置lysphp\core\class\lys_tag.class.php

 $format = $type == 1 ? '%Y-%m' : '%Y年%m月';
    
    // 修改 GROUP BY 子句,添加 inputtime
    return $this->db->field("FROM_UNIXTIME(inputtime, '$format') AS pubtime, count(*) AS total,inputtime")
        ->where('`status`=1')
        ->group("FROM_UNIXTIME(inputtime, '$format'), inputtime")
        ->order('pubtime DESC')
        ->limit($limit)
        ->select();
}
// ... 已有代码 ...





相关内容

文章评论

表情

共 0 条评论,查看全部
  • 这篇文章还没有收到评论,赶紧来抢沙发吧~

评论排行榜

热门标签

0.0171s