mysql - MySQL版本升级时GROUP BY无效

标签 mysql

当我将 ubuntu 从 15.10 升级到 16.04 时,我的 yii 项目出现此错误:

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'v4master.A.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by. The SQL statement executed was:

sql代码如下:

 $sql = "SELECT A.*,B.`type_name` FROM `".$this->tbl_auth_user_items."` A 
                INNER JOIN `".$this->tbl_auth_context_types."` B ON A.`type_id` = B.`type_id` 
                WHERE A.`user_id` = '".$user_id."' GROUP BY A.`type_id`, A.`type_value` ORDER BY A.`type_id` DESC";
         return $this->_db->createCommand($sql)->queryAll(); 

最佳答案

在 Mysql 上运行此查询;

set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

关于mysql - MySQL版本升级时GROUP BY无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47010581/

相关文章:

Python MySQL更新语句不起作用

mysql - MySQL 中 JavaScript 的 encodeURI 组件的等效项是什么?

python - 将 URL 中的信息保存到 MySQL 数据库

php - 使用 PHP PDO 从 CSV 插入来自 mysql 的数据

Mysql 按时间间隔和日期分组

mysql - 线程消息的 SQL 查询

python - 阿拉伯字体未使用 python 插入 mysql

mysql - 选择行匹配计算

mysql - 如何在 MySQL Workbench for Mac 中正确显示 unicode 字符?

php - MySQLi API 以及事务如何工作和提交