今天把网站的mysq版本更新到最新版本了为5.7 在查询语句的时候出现了一个错误语句 :
ORDER BY clause is not in GROUP BY clause and contains nonaggregated column ‘g2yx_yy.u.login_time‘ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
这个语句的错误是 order by 的语句中 没有依赖于group by语句中 下面是我之前写的错误语句
$myGameData = Db::name(‘user_played‘) ->alias(‘u‘) ->join(‘game g‘,‘g.id = u.game_id‘) ->join(‘area a‘,‘a.id = u.area_id AND a.game_id = u.game_id‘) ->field($condition[‘field‘]) ->where($condition[‘where‘]) ->group(‘u.area_id‘) ->order(‘u.login_time DESC‘) ->select(); 上面也说到了为啥报错 后面把sql语句变为
$myGameData = Db::name(‘user_played‘) ->alias(‘u‘) ->join(‘game g‘,‘g.id = u.game_id‘) ->join(‘area a‘,‘a.id = u.area_id AND a.game_id = u.game_id‘) ->field($condition[‘field‘]) ->where($condition[‘where‘]) ->group(‘u.area_id,u.login_time‘) ->order(‘u.login_time DESC‘) ->select(); 就能把问题解决了
时间: 2024-11-05 13:32:01